문제

I am have following SOAP example message:

     <?xml version="1.0"?>
     <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
     xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
     <SOAP-ENV:Body>
     <CREATE__CompIntfc__SUPPORT_DOC_TBL>
        <SUPPORT_DOC_ID>POLICE</SUPPORT_DOC_ID>
        <SUPPORT_DOC>
            <DESCR>Police Report</DESCR>
            <DESCRSHORT>Police</DESCRSHORT>
        </SUPPORT_DOC>
    </CREATE__CompIntfc__SUPPORT_DOC_TBL>
</SOAP-ENV:Body>
 </SOAP-ENV:Envelope>

and i need parse element. I am writig following code for this task but's its not working:

                  File inputXML=new                 File("/home/igor/IdeaProjects/jdomtest/src/main/resources/example.xsd");
    SAXBuilder saxBuilder=new SAXBuilder();
    try{
        Document rootElement=saxBuilder.build(inputXML);
        Element element=rootElement.getRootElement();

    Namespace ns=Namespace.getNamespace()
      List<Element> list=element.getChildren("Body");
 System.out.print(list.size());

  for (int i=0;i<list.size();i++){
  Element el = (Element)list.get(i);
    System.out.println(el);
   }

    }catch (Exception exp){
        exp.printStackTrace();
    }

But it's not any wirting on screen

도움이 되었습니까?

해결책

The Body element is in the http://schemas.xmlsoap.org/soap/envelope/ namespace, but you're using the single argument getChildren method which looks for elements in no namespace. You need to pass an appropriate Namespace to the two-argument version of getChildren.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top