Im using the following code for xml node extraction , But im getting the nullpointer exception
<root>
<place >
<city> aaaaaa </city>
<state / >
<country> zzzzzzzz </country>
<place>
</root>
I have tried the following code
NodeList nodeList = (NodeList)xPath1.compile(temp).evaluate(xmlDocument,XPathConstants.NODESET);
TempFlat = nodeList.item(0).getFirstChild().getNodeValue();
and i have googled and got this
NodeList nodeList = (NodeList)xPath1.compile(temp).evaluate(xmlDocument,XPathConstants.NODESET);
Node nValue = (Node) nodeList.getFirstChild();
where temp is my xpath . Which is readable from a file. example
/root/place/city
/root/place/city
/root/place/city
but for this im getting the following error
E:\Work\java\test.java:80: cannot find symbol
symbol : method getFirstChild()
location: interface org.w3c.dom.NodeList
Node nValue = (Node) nodeList.getFirstChild();
^
1 error
I found that , this is because <state / > is empty . How can i solve this . Can anyone help me
NOTE : I have found the reason for the 2nd error i have posted , But i need to solve the Null Pointer exception
<city>related to it? Edit your post to show the document structure all the way back to the root.