Reputation: 30
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
Upvotes: 0
Views: 1181
Reputation: 122414
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
.
Upvotes: 1