Hallo,
ich habe eine XML.
..
<a val = XX>
<b val=1>
<b val=2>
</a>
..
Die lese ich wie folgt aus:
Meine Frage, wie kann ich einen neuen b-Tag nach dem letzten b-Tag (val=2) einfügen?
ich habe eine XML.
..
<a val = XX>
<b val=1>
<b val=2>
</a>
..
Die lese ich wie folgt aus:
Code:
public static void main(String[] args) throws ParserConfigurationException,SAXException,IOException,XPathExpressionException { DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance(); DocumentBuilder db=dbf.newDocumentBuilder(); Document doc=db.parse(new File("g:\\test.xml")); doc.getDocumentElement().normalize(); XPathFactory factory=XPathFactory.newInstance(); XPath xpath=factory.newXPath(); XPathExpression expr=xpath.compile("//a"); NodeList nl=(NodeList)expr.evaluate(doc,XPathConstants.NODESET); for(int i=0;i<nl.getLength();i++) { //tue etwas } }
Comment