Package banphr; 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. "E: /program/bankemhr/1.xml")); // Reads 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.setttribute (a); //Item.Addattribute (A); "Name", "New Item" ); // Change the old attribute value string indent = ""; // Inditive symbol boolean newlines = false; // Does the new line XMLOUTTER OUTP = New XMLOUTPUTTER (Indenter, newlines, "GB2312"); // Construct new Output Outp.output (DOC, New FileoutputStream ("E: /PROGRAM/Bankemhr/2.xml")); // Output to 2.xml file}}