XML is a global structured language, which is increasingly favored by people, and various development platforms (such as Microsoft Studio series, Oracle series, Inprise Borland series, etc.) also support XML development as one of the propaganda slogans. Since the e-government development of the author has an earlier introduction of XML, it tastes many sweets, using XML data exchange information in many projects, saves many troubles, do not use the data format of the lock, easy to use XML data easy Expression, also facilitates first-line developers track debugging.
In XML applications, the most commonly used most practical is the read and write of the XML file, so the author briefly analyzes through a simple XML file reading. The XML files that can be established in any text editor, similar to the HTML structure, but XML semantics is strict, and the starting mark must be paired, such as "
XML Version = "1.0" encoding = "GB2312"?>
After the preparation work is finished, the Java code that will begin to write a qualitative. In order to save information read from the XML file, you need to build a simple bean to save the student information, named StudentBean, the code is as follows:
Public class studentbean {private string sex; // Student gender private string name; // Student Name Private Int Age; // Student Age Private String Phone; // Phone Number Public Void SetSex (String S) {SEX = S;} Public Void setName (String s) {name = s;} public void setage (} public void setphone (string s) {phone = s;} public string getsex () {Return SEX;} public string GetName () {Return Name;} public int getage () {return age;}}}}}}}}} public string getPhone ()} public
After writing XML test classes, the author named XMLTEST, in order to read and write XML files, need to import as follows, "//", for note, the author's environment is JDK 1.3.1_04, in JDK 1.4.0 The test also passed the XML interpreter with Apache's crimson, can go to the Apache home page to upload.
Import java.io. *; // Java foundation, containing various IO operations import java.util. *; // java basic package, including various standard data structures Import javax.xml.Parsers. *; // XML Analytical interface import org.w3c.dom. *; // XML DOM implementation import org.apache.crimson.tree.xmldocument; // write XML file to be used