Package com.test;
Import org.jdom. *; import org.jdom.Output. *; import org.jdom.input. *;
Import java.io. *; import java.util.list;
Public class jdomesample {public static void main (string [] args) throws exception // throws {SaxBuilder SB = new Saxbuilder (); // New FileInputStream (New FileInputStream) if there is any exception. "1.xml")); // Read 1.xml
Element root = doc.getroterElement (); // Get the root node, is the
For (int I = 0; i
ELEMENT SUB = Item.getChild ("Sub"); // Get the specified child node string text = sub.gettext (); // acquire 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 child node under the root node
Attribute A = New Attribute ("Started", "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 resulting a new line XMLOUTPUTTER OUTP = New XMLOUTPUTTER (Indenter); // Construct a new output stream Outp.output (DOC, New fileoutputStream ("2.xml")); // Output to 2.xml file}}