JDOM reads and writes an example of XML

xiaoxiao2021-03-06  35

Effect: Read and modify from 1.xml, then write 2.xml, two XML documents are as follows 1.xml --------------------- --------------- SUB ITEM 1 sub item 2 2.xml -------------- ------------------------ new item0 node list list = root.getchildren () in the example (); // Get all the nodes in the next layer of the root node into Li FOR in the ST class (INT i = 0; i " Name; element sub = item.getchild ("sub"); / / get the specified child node string text = sub node in the current node (); // obtain the contents of the specified child node System.out.println ("SUB ->"

text); sub.settext ("new item" string.valueof (i)); // change the content of the child node} element item = (element) list.get (0); // get the first root node A child node attribute a = new attribute ("start", "true"); // Add a new attribute item.addattribute (a); item.setttribute ("name", "new item"); // change the old Attribute value string indent = ""; // Inditive symbol Boolean newlines = false; // Does the new line XMLOUTPUTTER OUTP = New XMLOUTPUTTER (IND, NewLines, "GB2312"); // Construct new output stream Outp.output (DOC, New FileOutputStream ("2.xml")); // Output to 2.xml file}}

转载请注明原文地址:https://www.9cbs.com/read-53128.html

New Post(0)