I'm trying to get the numbers from the String tags only. Right now, the Java program thinks the string tags contain null. Thanks for the help in advance!
Here is the XML
<?xml version="1.0"?>
<ArrayOfstring xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<string>6540321</string>
<string>6540322</string>
<string>6540323</string>
<string>6540324</string>
<string>6540325</string>
</ArrayOfstring>
Here is what I've tried
public static void toOrderListFromXML() throws ParserConfigurationException, SAXException, IOException {
File fXmlFile = new File("test.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
org.w3c.dom.Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("string");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
System.out.println("Order number: " + eElement.getNodeValue());
}
}
}
Output:
Root element :ArrayOfstring
Current Element :string
Order number: null
Current Element :string
Order number: null
Current Element :string
Order number: null
.......................
.......................
Here is the tutorial I attempted to follow: http://www.java2s.com/Code/Java/XML/ParseanXMLstringUsingDOMandaStringReader.htm