I'm new to Java and need some help. I have a XML that looks like:
String pXML =
"<root>
<x>1</x>
<x>2</x>
<x>3</x>
<x>4</x>
</root>"
And I would like to get a List object that contains all of the values inside x tag.
I've tried with javax.xml.parsers.DocumentBuilderFactory:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = (Document) builder.parse( new InputSource( new StringReader(pXML) ) );
Node n = document.getFirstChild();
NodeList n1 = n.getChildNodes();
//and then I go through all the nodes and insert the values into a list
But this doesn't contain the x nodes.