Answer the question
In order to leave comments, you need to log in
I parse xml into Java, I get null. How to do it right?
I parse this xml:
<?xml version="1.0"?>
<store>
<object>
<id>1</id>
<counter>2</counter>
<isCommon>false</isCommon>
<raw>А</raw>
<childs>
</childs>
<types>
</types>
</object>
</store>
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
Document doc;
try {
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(new File(xmlfile));
}catch(Exception e){
System.out.println(e.getMessage());
System.exit(1);
return;
}
NodeList nList = doc.getElementsByTagName("object");
Node ObjectItem = nList.item(0);
Element element = (Element)ObjectItem;
Sytem.out.println(element.getElementsByTagName("counter").item(0).getNodeValue());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question