0
要清楚,我的xml及其XPath是动态的,任何事情都可能发生,因此没有硬编码的值来解析XPath中的XML值。这是我构建的XML和XPath。从命名空间xpath获取XML值
String xml = "<soapenv:Envelope xmlns:com=\"http://com\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body><com:addition><com:a>1</com:a><com:b>1</com:b></com:addition></soapenv:Body></soapenv:Envelope>";
Document doc = UtilityFunction.createXMLDocument(xml);
System.out.println("Value "+XPathFactory.newInstance().newXPath().compile("//soapenv:Envelope[1]/soapenv:Body[1]/com:addition[1]/com:a[1]").evaluate(doc).toString());
空的正在打印。我如何使用命名空间从xpath获取XML值。如何在编译中启用命名空间。
[如何检索XML的可能重复使用包含Java中名称空间的XPath的数据?](http://stackoverflow.com/questions/8221652/how-to-retrieve-xml-data-using-xpath-which-contains-namespace-in-java) – aalku
库XPathFactory属于哪个?是JDOM2吗? – akhikhl
javax.xml.xpath.XPathFactory工厂 –