Take the Sample1.xml file as an example, let's see how to increase the capacity of "disk disk2" to 20G. XML Version = "1.0" Encoding = "UTF-8"?>
Public class test3 {public static void main (string args []) {xmlproperties xp = new xmlproperties ("Sample1.xml"); system.out.println (xp.getproperty ("Disk2.capacity"); xp.setproperty "Disk2.capacity", "20g"); System.out.Println ("OK"); system.out.println (xp.getproperty ("Disk2.capacity");}} Run: C: / Java> Java Test3 10g OK 20G Finally, please see: Xmlproperties.java (from jivejdon2.6, please use the jdom.jar compile operation) Import Java.IO. *; Import Java.util. *; import org.jdom *;. import org.jdom.input *;. import org.jdom.output *;. public class XMLProperties {private File file; private Document doc; private Map propertyCache = new HashMap (); public XMLProperties (String File) {this.file = new file (file); try {saxbuilder builder = new saxbuilder (); // dataunformatfilter format = new dataunformatfilter (); // builder.setXMLFILT ER (Format); DOC = Builder.build (New File (File));} Catch (Exception E) {System.err.Println ("Error Creating XML Parser IN" "PropertyManager.java); E.PrintStackTrace );}} public String getProperty (String name) {if (propertyCache.containsKey (name)) {return (String) propertyCache.get (name);} String [] propName = parsePropertyName (name); Element element = doc.getRootElement (); For (int i = 0; i Element.getchild (propName [i]); if (element == null) {return null;}} string value = element.getText (); if ("" .Equals (value)) {Return null;} else {value = value.trim (); propertyCache.put (name, value); return value;}} public String [] getChildrenProperties (String parent) {String [] propName = parsePropertyName (parent); Element element = doc.getRootElement (); For (int i = 0; i } Public void deleteProperty (String name) {String [] propName = parsePropertyName (name); Element element = doc.getRootElement (); for (int i = 0; i