The so-called JDOM, the simplest understanding method is Java XML = JDOM. An example of a simple operation XML is provided below.
1. The following is an XML file used by the example:
/ **
* Located in the root directory of the C drive
* ABC.XML
** /
xml version = "1.0" encoding = "gb2312"?>
2, procedure for operating XML
/ **
* Myjdom.java
** /
Package com.test; import org.jdom. *; import org.jdom.input. *; import org.jdom.output. *;
Import java.io.fileinputStream; import java.io.fileoutputstream; import java.util.list;
Public class myjdom {
Public static void main (string [] args) throws exception {saxbuilder sb = new saxbuilder (); // Establish constructor Document Doc = Sb.Build (New FileInputStream ("c: //abc.xml")); ///// Read in the specified file
Element root = doc.getrootelement (); // Get root node list = root.getchildren (); // put all child nodes under the root node into list
For (int I = 0; i System.out.println ("------------------------"); ELEMENT ITEM = (Element) list.get (i); // Get a node instance String name = item.getattribute ("name"). GetValue (); // acquire attribute value System.out.println ("Name ->" Name; ELEMENT SUB = Item.getchild ("Title"); // Take the word point String text = sub.gettext (); // get the value of the current node System.out.println ("Title ->" Text); Element Sub2 = item.getchild ("content"); string text2 = sub2.gettext (); System.out.println ("Content ->" TEXT2); ELEMENT SUB3 = Item.Getchild ("email"); string text3 = Sub3.getText (); system.out.println ("email ->" text3);}}}