I need to parser an Xml Document and store the values in Text File, when i am parsing normal data (If all tags have data) then its working fine, but if any tag doesnt have d
This code should work:
// getNode function
private static String getNode(String sTag, Element eElement) {
//if sTag exists(not null) I get childNodes->nlList
if (eElement.getElementsByTagName(sTag).item(0)!=null){
NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
//check if child (nlList) contain something
if ((nlList.getLength() == 0))//if the content is null
return "";
//if child contains something extract the value of the first element
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
}
return "";
}