JDOM usage example

xiaoxiao2021-03-06  42

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

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

New Post(0)