私はJavaを初めて使用するので、助けが必要です。次のようなXMLがあります。
String pXML =
"<root>
<x>1</x>
<x>2</x>
<x>3</x>
<x>4</x>
</root>"
そして、xタグ内のすべての値を含むListオブジェクトを取得したいと思います。
私は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
ただし、これにはxノードは含まれていません。