I can already add XML data of the existing data, I am very confused about this, Let's say my code is the new document document (). NewDocument (); // db.newDocument (); // Create document element root = doc.createElement ("employee")
document doc = document builder factor. Experience (). NewDocumentBuilder ()); // cretae elements doc.appendChild (root); Comment cmt = doc.create Comment ("Employee Details"); // add a comment to xml root.appendChild (cmt); Element employee = Doctor.Scent element ("employee"); // Create Element //employee.appendChild(doc.) Root.appendChild (employee); Attr genderAttr = doc.createAttribute ("Gender"); System.out.print ("Enter your gender:"); String gender = br.readLine (); GenderAttr.setValue (Gend); Employee.setAttributeNode (genderAttr); System.out.print ("Enter First Name:"); String child = br.readLine (); Element FName = doc.createElement ("first name"); FName.appendChild (doc.createTextNode (child)); // set xml text worker .appendChild (FName); System.out.print ("Enter Last Name:"); String child 1 = breadlines (); Element LName = doc.createElement ("lastname"); LName.appendChild (doc.createTextNode (child1)); Employee.appendChild (LName); //root.appendChild(employee); //doc.appendChild(root); // Transformerfifferent TF = TransformerFeature to write on file / screen New Intens (); Transformer tr = TF Nuu Transformers (); Tr.setOutputProperty (OutputKeys.INDENT, "Yes"); DOMSource source = new DOMSource (doc); // source // file store order = new file ("src" + file. Separator + "XMLPercing" + file. Separator + "XMLPERSSE 1.xml"); // Get the file StreamResult res = new stream result (new file ("src" + file. Separator + "XMLPercing" + file. Separator + "XMLPerse 1.xml"); // Destination Tr. Transsoform (source, race); // write on file and I can easily parse and update but I do not understand how can I add the previous data Please help me
It is very easy to say, you want to add your XML to the new employee . Root nodelight root list = doc.getElementsByName ("employee") is used by simply using getElementsByName () as // instead of creating a new root Will be able to; Node root = rootList.item (0); Element employee = Doctor.Scent element ("employee"); // Create new element root. AppendChild; //
No comments:
Post a Comment