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.