Nothing for these two days, starting with Java, wanting to write a mail sent by the email, think of what parameters to save, how to save? Suddenly think of the XML file, good, use this.
After researching, I feel that Dom4j is good, OK is it, it is it, and the code is posted (modified), write writing, there is not enough, for reference only:
/ * * Created on 2005-4-14 15:26:04 * modify no 2005-4-19 16:06:12 * /
/ ** * @Author zxub * / import java.io.file; import java.io.filewriter; import java.Net.malForMedurLexception; import java.util.ITerator; import java.util.list; import org.dom4j. Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; public class OperaXML {private Document document = null ; public static boolean fileExist (String fileName) {java.io.File objFile = new java.io.File (fileName); if (objFile.exists ()) {return true;} else {return false;}} public void createXMLFile (String XMLFileName, String rootName) {if {this.document = DocumentHelper.createDocument () (fileExist (XMLFileName)!); Element element = this.document.addElement (rootName); // add comments to element.addComment (String) / / Add Node Element.Addelement (String); // Add to Properties Element.addattribute (Name, Value); // Setting content Element.Settext (String); //system.Println ("file created! "); Savexmlfile (XMLFileName); Else {system.out.println ("File Exist!");}} public void addchild (String FatherPath, String ChildName, String ChildValue) {if (this.Document == null) {system.out.println ("HAS Not GET XML File, Add Err! "); Return;} list = this.document.selectnodes (FatherPath); Iterator iter = list.iterator (); if (izer (ore.hasnext ()) {ELEMENT ELEMENT = (Element) iter .next (); element childlement = element.addelement (childname); ChildElement.Settext (childValue);} else {system.out.println ("Father Node Does Not Exist! Add Error!");
}} Public void modifyNode (String XMLFileName, String nodePath, String nodeValue, String newValue) {if (this.document == null) {System.out.println ( "Has not get XML file, modify err!"); Return; } List list = this.document.selectnodes (nodePath); item = list.ITERATOR (); boolean nodeexist = false; while (ore) {Element Element = (Element) ney.next (); if (); ELEMENT.GETTEXT (). Equals (nodevalue)) {ELEMENT.SETTEXT (NodeExist = true;}}}}}}}}}}}}}}}}}} 店 i (! ") {system.out.println (" Target Node Does NOT! Modify Error! "); }}} Public void savexmlfile (String XMLFileName) {if (this.Document == null) {system.out.println ("HAS NOT GET XML File, Save Err!"); Return;} Try {/ ** In Document Content write file * / XMLWRITER WRITER = New XMLWRITER (New File (XMLFileName)); Writer.Write (this.Document); Writer.close ();} catch (exception ex) {system.out .println (ex.getMessage ());}} public void read (String XMLFileName) { if (fileExist (XMLFileName)) {SAXReader reader = new SAXReader (); try {this.document = reader.read (new File (XMLFileName));} catch (MalformedURLException e) {System.out.println (e.getMessage ( )));} Catch (documentException e) {system.out.println (E.GetMessage ());}} else {system.out.println ("XML File Does Not Exist, Read Error!"); System.exit 0);}} public element getrootelement () {if (this.document == null) {system.out.println ("Has Not get XML File, Get Root ERR!"); Return null;} return null;} return null; PUBLIC STRING GETNODEVALUE (STRING NODEPATH) {IF (this.Document ==