First, if you are not interested in Java or say that your host does not support Java or if you don't plan to learn, please don't waste time here. Please install the Java execution environment and PHP combination. Specific reference http://www.phpx.com/happy/thr78795.html or download http://www.javax.org/download/php_java.rar I wrote Readme.txt Description Documentation, this compression package is a simple example. To download my Java source code, please go to http://www.javax.org/download/javaxml.rar has other questions, please go to http://www.javax.org/. At first I wanted to parse XML with PHP, but I found that PHP should be a bit troublesome, as if PHP5 is convenient, but I have no installation here, or 4.3. Later, I saw an article (http://www-900.cn.ibm.com/index.shtml), I can use Java to do, so I have tried it now. The XML file to be parsed: first.xml, the content is as follows: XML Version = "1.0" encoding = "utf-8"?>
Let's look at PHP file parsing time:
"; // get the first node Name tag value echo $ javaxml-> getValue (" age ")."
"; // get the first node AGE tag value $ javaxml -> setValue, "Dad"); // Set the first node Name tag value is big Dad $ javaxml-> get (1); // Here you get the second node echo $ javaxml-> GetValue ("name"). "
"; // get the second node Name tag value Echo $ javaxml-> getValue ("age"). "
"; // get the second node AGE label What is the value?> $ Javaxml-> get (0); get the node location, such as my XML file has two groups
import org.jdom *; import org.jdom.output *; import org.jdom.input *; import java.io. *; import java.util *; / * Author:.... Umbrellas: 2004/12 / 28 * / public class JavaXml {public String path = null; public String XmlFileName = null; public SAXBuilder sax = null; public Document doc = null; public Element root = null; public List xlist = null; public Element e = null; public Element value = null; public String getTest () {return new String ( "haha");} public JavaXml () {} public String init () {InputStream is = getClass () getResourceAsStream ( "global.properties");. Properties DBProps = new Properties (); try {dbprops.load (IS);} catch ("error file");} this.path = dbprops.getProperty ("xmlpath"); return ("ok" );} public void get (int class) {this.e = (element) xlist.get (child);} public string getValue (String name) {this.Value = E.GetIld (name); return this.Value. getText ();} public void setValue (String name, String value) throws Exception {this.value = e.getChild (name); this.value.setText (value); XMLOutputter xmlout = new XMLOutputter (); xmlout.outp ut (doc, new FileOutputStream (path XmlFileName));} public void Parse (String XmlFileName) throws Exception {this.XmlFileName = XmlFileName; this.sax = new SAXBuilder (); this.doc = sax.build (new FileInputStream ( Path XMLFileName); this.root = doc.getrootElement (); this.xlist = root.getchildren ();}} But when you use it, you don't need to write Java code, as long as you configure the Java execution environment. If you don't understand anything, please keep it, so I don't know if it is more troublesome. Please express your opinion. If you think it can, I will continue to improve the Java class, provide more Analyze the function of XML.