Creating & Appending Nodes in XML

admin

Administrator
Staff member
Hi,

I am using JAXP1.1 for the creation/parsing etc., of xml through Java code in one of my projects.. When I give the following codec for creating and Appending a new node for the existing xml file, it is not giving any errors in the program but, when I open the xml file for viewing the changes. The changes are not at all affected in the xml file. I think I might have missed 1 or 2 steps in b/wn, can any body tell me what I hv missied here or tell me if at all there is any other way.... I will be better if you can solve with the same. Following is my codec:

------
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(convertToFileURL(filename));
NodeList nl = doc.getElementsByTagName(code);
Node nod=nl.item(0).appendChild(doc.createTextNode("G555007"));
Node nod1=nl.item(0).insertBefore(doc.createTextNode("G555007"), nl.item(1));
-------
 
Back
Top