JDOM is an open source pure Java API for rapid development of XML applications, and JDOM represents an XML document as a tree, including elements, properties, descriptions, processing instructions, text nodes, CDATA sections, and more. JDOM can access any part of the tree at any time. All different nodes in the tree are specific classes. You can download the latest version of JDOM at http://jdom.org. After downloading, the JAR file of JDOM is the file jdom.jar in the build directory, and will join the classpath.
The most important package in JDOM is org.jdom, which mainly has the following types of operations for XML documents: Attribute CData Comment Docty Document Element Entityref Namespace Processinginstruction Text See how JDOM creates XML document: import java.io. *; import org.jdom *;. import org.jdom.input *;. import org.jdom.input *;. import org.jdom.output *;. public class test1 {public void BuildXMLDoc () throws IOException, JDOMException {Element root , E1, E2; Document Doc; Root = New Element ("EMPLOYEES_INFORMATION"); // Building a root element DOCTY TYPE = New DOCTYPE ("Employees_information", "Employees.dtd"); // Document Type DOC = New Document Root, Type); // Then create an XML document object E1 = new element ("name") with root; // Create an element E1, set content, attribute E1.SetText ("cyb"); E1.SetAttribute ("INDEX "," 1 "); root.addcontent (e1); E2 = new element (" name "); // Create element E2, set content, attribute E2.SetText (" ay Shen "); E2.SetAttribute (" INDEX "," 2 "); root.addcontent (e2); E2.AddContent (New Comment (" good ")); // Add a note // Add element root in a concise form .addContent ("name"). AddContent ("Dychen"). SetAttribute ("INDEX", "3")); // xmloutputter xmlout = new xmloutputter (); // xmlout.set " ; // xmlout.setnewlines (TRUE); xmloutputter Xmlout = new xmloutputter (", true); // After the element is wrapped, each layer is constantly rumored two grid xmlout.setencoding (" GB2312 "); XMlout.output ( DOC, New FileOutputStream ("Test1.xml"));} public static void main (string [] args) {try {test1 s1 = new test1 ();