Jdom reading example

xiaoxiao2021-03-06  40

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 node list list = root.getchildren () in the example; // Get all the nodes in the next layer of the root node into the list class

For (int I = 0; i " Name);

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}}

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

New Post(0)