JAXP parsing XML based on DOM model

Source: Internet
Author: User
Tags cdata object model

XML parsing is usually divided into two types:

The 1.DOM parsing (Document Object model, the Documentation Objects module), which is a recommended way for the organization to process XML.

2. The other is sax (simple APIs for XML).

Of course, IBM backed out of JAXB, based on JavaBean XML parsing, but this article describes the DOM model parsing principle and the Java-built API (JAXP---java API for XML processing) Parsing XML through the DOM model, because JAXP is a technique in the Java EE specification, so it is necessary for apes to master this API as a Java program.

One: What is DOM?

Document Object model, which is a recommended way for the organization to process XML.

The DOM model defines the standard way to access and manipulate XML documents. (That is, defining a specification for accessing an XML document)

Let's look at an XML document:

<?xml version= "1.0" encoding= "UTF-8"?>
<!--to write a DTD file inside an XML document-->
DOCTYPE Bookstore [
  <! ELEMENT Bookstore (book) +>     
  <! ELEMENT Book (title,author,year,price) >
  <! ELEMENT title (#PCDATA) >
  <! ELEMENT author (#PCDATA) >
  <! ELEMENT year (#PCDATA) >
  <! ELEMENT Price (#PCDATA) >
  <! Attlist Book category CDATA #REQUIRED >
  <! attlist title lang CDATA #REQUIRED >
]>
    
<bookstore>
  <book category= "operating system" >
    <title lang= "Chinese" > Bird's Kitchen </title>
    <author> bird brother </author>
    <year>2005</year >
    <price>89.5</price>    
    </book>        
</bookstore>

This is a valid (well-formed, DTD-bound) XML document.

When we use DOM to parse the XML document, the XML document forms a tree structure in memory, and each component in the XML document is a node.

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.