我是Java新手,需要一些帮助。 我有一个XML看起来像:Java string to xml to list
String pXML =
"<root>
<x>1</x>
<x>2</x>
<x>3</x>
<x>4</x>
</root>"
而且我想获得一个包含所有X标签内的值的列表对象。
我试着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个节点。
我怀疑引号是导致解析器跳过所有的XML。 – 2013-03-26 13:47:33
不,我得到的pXML对象作为输入参数,这是为了了解xml的外观...... – informerica 2013-03-26 13:57:11