XML file for JDOM operations (revised version of Pharaoh)

Source: Internet
Author: User

This article is good ~ The basic operations of JDOM are instantiated. However, due to the outdated JDOM versions used by the author at that time, some code compilation errors may occur! Chinese support is not good! Therefore, Pharaoh modified the program on the basis of the original author! The compilation error and Chinese garbled characters are closed. Published for your learning and use.
Test environment: jdom1.0, weblogic 8.1sp2, and tomcat (a good JSP running platform) 5.0 and IE 6. 0
// ===================================================== Start of the body ==== =============================================/
Java + xml (standardization is getting closer and closer) = JDOM!
This is the goal of the JDOM designer. If you have used annoying SAX or DOM to process xml (standardization is getting closer and closer), you will know why JDOM or JAXB is required. At this year's (2002) JavaOne conference, Jason Hunter, the main founder of JDOM, gave a wonderful speech about JDOM Technology, titled JDOM Makes xml (standardization is getting closer and closer) Easy.
Obtain and install JDOM
In the http://jdom.org, you can download the latest version of JDOM. Take the JDOM 1.0 2-step version as an example. After downloading and decompressing, The JDOM jar file is the jdom. jar file under the build Directory, which is added to the class path. In addition, JDOM also requires support for jar files such as xerces. jar and jaxp. jar in the lib directory. If the following error occurs during use:
Java. lang. NoSuchMethodError
Or
Java. lang. NoClassDefFoundError: org/xml (standardization is getting closer and closer)/sax/SAXNotRecognizedException
You need to ensure xerces. jar files are located in other xml (standardization is getting closer and closer) classes in CLASSPATH, such as before JAXP or Crimson, these class files, including previous versions of xerces, it may not support SAX2.0 or DOM Level 2. As a result, the above error occurs.

A simple example
The JDOM processing method is similar to DOM, but it is mainly implemented using SAX, so you don't have to worry about processing speed and memory. In addition, there are almost no interfaces in JDOM, and all the classes are real classes without class factory classes.

Below is the xml (standardization is getting closer and closer) file used by the instance: Myxml (standardization is getting closer and closer). xml (standardization is getting closer and closer)

<? Xml (standardization is getting closer and closer) version = "1.0" encoding = "UTF-8"?>
<Library>
<Book>
<Title> getting started with Java programming </title>
<Author> Zhang San </author>
<PRESS> electronic publishing house </PRESS>
<Price> 35.0 </price>
<Publication date> 2002-10-07 </publication date>
</Book>
<Book>
<Title> application of xml (standardization is getting closer and closer) in Java </title>
<Author> Li Si </author>
<PRESS> hope press </PRESS>
<Price> 92.0 </price>
<Publication date> 2002-10-07 </publication date>
</Book>
</Library>


Below is the Bean that operates the xml (standardization is getting closer and closer) file: xml (standardization is getting closer and closer) Bean. java

Package jdom. test;

/**
* Xml (standardization is getting closer and closer) read/write operation Bean
*/
Import java. io .*;
Import java. util .*;
Import org. jdom .*;
Import org. jdom. output .*;
Import org. jdom. input .*;
Import javax. servlet .*;
Import javax. servlet. http .*;

Public class xml (standardization is getting closer and closer) Bean {
Private String bookname, author, pub, price, pubdate;

Public String getbookname (){
Return bookname;
}

Public String getauthor (){
Return author;
}

Public String getpub (){
Return pub;
}

Public String getprice (){
Return price;
}

Public String getpubdate (){
Return pubdate;
}

Public void setbookname (String bookname ){
This. bookname = bookname;
}

Public void setauthor (String author ){
This. author = author;
}

Public void setpub (String pub ){
This. pub = pub;
}

Public void setprice (String price ){
This. price = price;
}

Public void setpubdate (String pubdate ){
This. pubdate = pubdate;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.