Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用XPath和XMLXPathAPI获取Soap主体_Java_Xml_Soap_Xpath - Fatal编程技术网

Java 使用XPath和XMLXPathAPI获取Soap主体

Java 使用XPath和XMLXPathAPI获取Soap主体,java,xml,soap,xpath,Java,Xml,Soap,Xpath,我在应用程序中使用XMLXPathAPI 这是我的soap请求 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="http://testwork/"> <soapenv:Header/> <soapenv:Body> <tes:sayHelloWorldFrom>

我在应用程序中使用XMLXPathAPI

这是我的soap请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="http://testwork/">
       <soapenv:Header/>
       <soapenv:Body>
          <tes:sayHelloWorldFrom>
             <!--Optional:-->
             <arg0>value</arg0>
          </tes:sayHelloWorldFrom>
       </soapenv:Body>
    </soapenv:Envelope>
但是结果是
result com.sun.org.apache.xml.internal.dtm.ref。DTMNodeList@19f76837


那么我做错了什么

XPathConstants.NODESET
指示API返回它找到的与查询匹配的结果的
NodeList

当您需要可变数量的匹配项时,这非常有用。您可以在列表上迭代

for (int index = 0; index < nodes.getLength(); index++) {
    Node node = nodes.item(index);
    //...
}
已更新

可能不需要做下面的事情就可以做到这一点,但是名字空间会影响我的大脑

创建
工厂后,将其名称空间感知设置为
false`,然后从搜索中删除节点名称空间上下文,例如

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
org.w3c.dom.Document doc = null;
try {
    doc = factory.newDocumentBuilder().parse(new File("Soap.xml"));

    XPathFactory xFactory = XPathFactory.newInstance();
    XPath xPath = xFactory.newXPath();
    Object result = xPath.compile("/Envelope/Body").evaluate(doc, XPathConstants.NODESET);
    NodeList nodes = (NodeList) result;
    System.out.println("Found " + nodes.getLength() + " matches");
    for (int index = 0; index < nodes.getLength(); index++) {
        Node node = nodes.item(index);
        System.out.println(node);
    }
} catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException exp) {
    exp.printStackTrace();
}
DocumentBuilderFactory=DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
org.w3c.dom.Document doc=null;
试一试{
doc=factory.newDocumentBuilder().parse(新文件(“Soap.xml”);
XPathFactory xFactory=XPathFactory.newInstance();
XPath=xFactory.newXPath();
Object result=xPath.compile(“/Envelope/Body”).evaluate(doc,XPathConstants.NODESET);
节点列表节点=(节点列表)结果;
System.out.println(“找到”+节点.getLength()+“匹配”);
对于(int index=0;index
XPathConstants.NODESET
指示API返回它找到的与查询匹配的结果的
NodeList

当您需要可变数量的匹配项时,这非常有用。您可以在列表上迭代

for (int index = 0; index < nodes.getLength(); index++) {
    Node node = nodes.item(index);
    //...
}
已更新

可能不需要做下面的事情就可以做到这一点,但是名字空间会影响我的大脑

创建
工厂后,将其名称空间感知设置为
false`,然后从搜索中删除节点名称空间上下文,例如

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
org.w3c.dom.Document doc = null;
try {
    doc = factory.newDocumentBuilder().parse(new File("Soap.xml"));

    XPathFactory xFactory = XPathFactory.newInstance();
    XPath xPath = xFactory.newXPath();
    Object result = xPath.compile("/Envelope/Body").evaluate(doc, XPathConstants.NODESET);
    NodeList nodes = (NodeList) result;
    System.out.println("Found " + nodes.getLength() + " matches");
    for (int index = 0; index < nodes.getLength(); index++) {
        Node node = nodes.item(index);
        System.out.println(node);
    }
} catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException exp) {
    exp.printStackTrace();
}
DocumentBuilderFactory=DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
org.w3c.dom.Document doc=null;
试一试{
doc=factory.newDocumentBuilder().parse(新文件(“Soap.xml”);
XPathFactory xFactory=XPathFactory.newInstance();
XPath=xFactory.newXPath();
Object result=xPath.compile(“/Envelope/Body”).evaluate(doc,XPathConstants.NODESET);
节点列表节点=(节点列表)结果;
System.out.println(“找到”+节点.getLength()+“匹配”);
对于(int index=0;index
for(int index=0;indexDocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(false); org.w3c.dom.Document doc = null; try { doc = factory.newDocumentBuilder().parse(new File("Soap.xml")); XPathFactory xFactory = XPathFactory.newInstance(); XPath xPath = xFactory.newXPath(); Object result = xPath.compile("/Envelope/Body").evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; System.out.println("Found " + nodes.getLength() + " matches"); for (int index = 0; index < nodes.getLength(); index++) { Node node = nodes.item(index); System.out.println(node); } } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException exp) { exp.printStackTrace(); }