XPath read root element returns null



Given an XML file like:



<source>
<element value="a">
<element value="b">
</source>


I'm trying to read the root element ("source") of the XML using Java and XPath:



public String parseExpression(Document doc) {
NodeList nodeList = (NodeList) xPath.compile("/").evaluate(
doc, XPathConstants.NODESET);
return nodeList.item(0).getFirstChild().getNodeValue();
}


However it returns null. Why ?

Thanks


No comments:

Post a Comment