1
给定一个XML文件,如:的XPath读根元素返回null
<source>
<element value="a">
<element value="b">
</source>
我试图读取使用Java和XPath的XML的根元素( “源”):
public String parseExpression(Document doc) {
NodeList nodeList = (NodeList) xPath.compile("/").evaluate(
doc, XPathConstants.NODESET);
return nodeList.item(0).getFirstChild().getNodeValue();
}
但是它返回null。为什么?
[DOMDocument getNodeValue()可能重复返回null(包含输出转义字符串)](http://stackoverflow.com/questions/12413450/domdocument-getnodevalue-returns-null-contains-an-output-escaped-串) – Joe 2014-11-04 12:10:14