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"?> jhgjg title> jhjg content> jhjh email> message> fdsa title> FASDF Content> fsadfa email> message> messages> 2, operate XML program / ** * 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 Specify file Element root = Doc.getrootElement (); // Get root node list = root.getchildren (); // put all child nodes under the root node in the list for for (int i = 0; i " 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);}}} Corenwang [original] Author Blog:
http://blog.9cbs.net/corenwang/