JDOM-based JSP application for processing database-to-XML Conversion

Source: Internet
Author: User

 

1. Introduction to JDOM

We know that DOM is the official W3C standard for expressing XML documents in a way unrelated to the platform and language. DOM and SAX APIs can be used to parse and process XML documents. Here we introduce JDOM, a pure java api Based on Tree operations. It should be said that it provides a set of solutions for parsing, creating, processing, and implementing XML.

These APIs are more intuitive than the methods provided by DOM and SAX APIs. programmers with JAVA experience will find JDOM very easy to master. JDOM is much easier to process XML than DOM, and it is more powerful than SAX.

The internal logic structure of JDOM is basically the same as that of DOM. For example, JDOM has Document, Element, Comment, and other Document node types. Each JDOM Document must have a Document node, and is the root node of the node tree. The root node can have subnodes or leaf nodes such as Comment and Text. Each node type in the JDOM document corresponds to none of the Well-formed XML files. This provides an operational basis for us to use JDOM to convert databases to XML documents.

Advantages of JDOM:

The Document declaration of JDOM clearly shows the advantages of using JDOM. The JDOM document declares that "JDOM references the 20/80 principle, that is, 20% of the effort is used to solve 80% of JAVA/XML problems ".

● JDOM is developed in JAVA and provides services for JAVA. It follows the JAVA code specifications and class libraries;

● Among the many programming languages, JAVA is an excellent platform for using XML, and XML is an excellent Data Representation Method for JAVA applications. JDOM APIs are pure JAVA APIs that are easier for JAVA developers to use;

● JDOM APIs are more intuitive than the methods provided by DOM and simplify interaction with XML. It is faster than DOM.

Org. jdom is a JDOM toolkit for java api operations.

In org. jdom, JAVA classes such as Document, Element, Comment, DocType, Attribute, and Text are provided. These classes are required to access and operate JDOM documents. We can use these classes to create, traverse, and modify JDOM documents.

In org. jdom. output, DOMOutputter and XMLOutputter are provided for processing the DOM tree form of the JDOM tree, XML document form output, and printing.

II. Environment Configuration

On my WINDOWS2000 system platform, Tomcat 4.1.18 and JDK 1.4.0 _ 02 are used as the development and testing platforms.

Use the "advanced" attribute of "My Computer" to add the following two Environment Settings CLASSPATH: ".; c: j2sdk1.4.0 _ 02libdt. jar; c: j2sdk1.4.0 _ 02lib ools. jar ;". Set PATH to ".; c: j2sdk1.4.0 _ 02in ;".

SQL SERVER JDBC driver: Put mssqlserver. jar in the LIB directory of TOMCAT.

3. obtain and install JDOM

Currently, JDOM is not included in SUN's JDK (I think JDOM will inevitably become part of SUN's JDK in the near future). We must manually download and set the JDOM environment.

In the http://www.jdom.org, you can download the latest version of JDOM. Here we download JDOM beta8. Download jdom-b8.zip and decompress it. The JDOM jar file is the jdom. jar file under the build directory. Copy the above file to the jre/lib/ext directory under the J2SDK1.4.0 _ 02 directory.

4. Use JDOM to convert SQL SERVER database to XML

1. create databases and tables

Here is an example of customer information conversion ?? "Basic customer information ". We place the data in the microsoft SQL SERVER 2000 database, and then use JSP and JDOM Technology to dynamically generate XML instance documents.

We created a data table CUSTOM in the Microsoft SQL Server database CUSTOM in advance. Its data structure is shown in the following table:

 

      Whether the field Name comment type is empty Name varchar (12) NOT NULLIDIDintNOT NULLCompany varchar (30) NOT NULLEmailTELvarchar (15) not null enter the following records into the database: nameIDCompanyEmail Liu's 001 company 1liu@yantai.com Jiang's 002 company 2jiang@yantai.net

2. Data Source settings

  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next Page

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.