Java 如何用JDOM解析SOAP
我有以下SOAP示例消息:Java 如何用JDOM解析SOAP,java,soap,jdom,Java,Soap,Jdom,我有以下SOAP示例消息: <?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__CompI
<?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>
警方
警察报告
警方
我需要解析元素。我正在为此任务编写以下代码,但它不起作用:
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();
}
File inputXML=new文件(“/home/igor/IdeaProjects/jdomtest/src/main/resources/example.xsd”);
SAXBuilder SAXBuilder=新SAXBuilder();
试一试{
documentrootelement=saxBuilder.build(inputXML);
Element=rootElement.getRootElement();
Namespace ns=Namespace.getNamespace()
List=element.getChildren(“Body”);
System.out.print(list.size());
对于(int i=0;i主体元素位于http://schemas.xmlsoap.org/soap/envelope/
namespace,但您使用的是单参数getChildren
方法,该方法不在任何名称空间中查找元素。您需要向双参数版本的getChildren
传递适当的namespace