// get the root, then get all the transactions // then get the last transaction... Element root = document.getDocumentElement(); NodeList nl = root.getElementsByTagName("transaction"); Node lastTransaction = nl.item( (nl.getLength()-1) );
// create a new element... Element descElement = createXMLElement( "DATA", txtData.getText());
// create another new element for the new transaction record... Element newTransaction = document.createElement("TRANSACTION");
// place the new "data" with the new transaction... newTransaction.appendChild(descElement);
// finally, place the new transaction in the document lastTransaction.appendChild(newTransaction);
...and the new transaction ends up in a place where I didn't expect it. I'm using the javax.xml.transform class to print out my document to screen to verify that the insert took place.
So...basically I need to know what I'm doing wrong. I need to be able to append new TRANSACTION element to my document.