JAVAsimpleXMLparsing(JAVA简单的XML解析)

更新时间:2023-06-05 00:33:54 阅读: 评论:0

蒜香生菜
JAVA simple XML parsing(JAVA简单的XML解析)
XML as a structured language universal, more and more popular, various platforms (such as Microsoft Studio ries, Oracle ries, Inpri Borland Series) are to support XML development as one of the slogan. Becau of the e-government development in the early introduction of the XML, so many have tasted the sweetness, in many projects using XML data exchange information, eliminating a lot of trouble, do not make complicated data format, easy to u XML data expression, but also conducive to the front-line developers debugging.
批号I have previously published related articles, such as "Delphi analysis of XML programming" a text, interested readers can go to the Google network () to arch, there are many media reprinted. Today, I would like to explore the Java programming in XML, and I hope it will help the new and old readers who are studying or want to learn XML programming.
电饭煲品牌In XML applications, the most commonly ud and most practical is the reading and writing of XML files, so the author makes a brief analysis by reading and writing a simple XML file. Can first establish follows the structure of the XML file in any text editor, similar to the HTML structure, but the mantics of XML is very strict, the starting marks must be paired, such as "" student roster "" and "" / "student ros
ter" corresponding, how much space there is no need to care, but generally to the indented form of writing easy to read. This file is l, you can open the test in any browr that supports XML, and if you enter correctly, you can e the tree reprentation structure of the file in the brow. If you are still unfamiliar with the structure of XML, it is recommended
to look at "Delphi analysis of XML programming" in a text on the XML file instructions.
< XML, version=, 1, encoding=, GB2312 > >
< student roster >
< student x = male >
< name > < / > name Li Hua
< age > >14</ > age >
< phone, >6287555</, phone >
< / > students开学第一课发言稿
< student x = male >
< > three < / > name name
< age > >16</ > age >
< phone, >8273425</, phone >
< / > students
< / student roster.
When the preparation was finished, then began to write the substantive JAVA code. To save the information read from the
XML file, you need to build a simple Bean to store student information, named StudentBean, as follows:
Public, class, StudentBean {
Private String x; / / gender
公费研究生
Private String name; / / the name of the student
Private int age; / / student age
Private String phone; / / telephone number
Public, void, tSex (String, s) {
Sex = s;
}
Public, void, tName (String, s) {
Name = s;
}
麻痹大意的意思石膏粉Public, void, tAge (int, a) {
Age = a;
}
Public, void, tPhone (String, s) { Phone = s;
}
Public, String, getSex () {
Return x;
}
Public, String, getName () {
Return name;
}
Public, int, getAge () {
Return age;
化工基础知识
}
Public, String, getPhone () { Return phone;
}
}
The test class after writing XML, I take this class named XMLTest to read and write XML files, you need to import the following JAVA package "/ /" after the notes, the environment is JDK 1.3.1_04, in JDK 1.4.0 test by the XML interpreter, with Apache Crimson, you can go to the Apache home page to upload.
Import java.io.*; the //Java ba package contains various IO operations
Import java.util.*; the //Java ba package contains various standard data structure operations
l.parrs.*; //XML parr interface
Import org.w3c.dom.*; DOM implementation of //XML
Import XmlDocument; / / write XML file to u
To save multiple student information,
You have to u a collection class (not a collection in the n only, and the t in JAVA is a collection of frames, including vectors, lists, hashes, etc.), where the Vector vector class is ud. Defined in the XMLTest test class, named
student_Vector. Then define two methods, readXMLFile and writeXMLFile, to read and write operations. The code reads as follows:
Private, void, readXMLFile (String, inFile), throws, Exception

本文发布于:2023-06-05 00:33:54,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/866114.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:第一课   电饭煲   研究生
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图