I want to parse the xml file to get the root element. Then append add the tag named first-name under that root tag. How do I do this ? This is what I have been doing right now :
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();
Element blobKey_E = document.createElement("first-name");
blobKey_E.appendChild( document.createTextNode( name ) );
// NOW APPEND blobKey_E to the root element
// After getting the root element from the xml in some directory
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new File("/home/non-admin/NetBeansProjects/Personal Site_Testers/web/xml/xml_1.xml"));
transformer.transform(source, result);
Will append
first-nameto the end of the DOM treeInserting into the first position is a little more difficult…
UPDATE