如何用JDOM解析SOAP

时间:2014-02-01 10:15:58

标签: 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__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();
    }

但这不是屏幕上的任何问题

1 个答案:

答案 0 :(得分:1)

Body元素位于http://schemas.xmlsoap.org/soap/envelope/命名空间中,但您使用的是单个参数getChildren方法,该方法在 no 命名空间中查找元素。您需要将适当的Namespace传递给getChildren的双参数版本。

相关问题