JAXP DOM: Difference between revisions
Line 18: | Line 18: | ||
==DOM Tree Nodes as Objects== | ==DOM Tree Nodes as Objects== | ||
The data structures referred to from the tree produced by a DOM parser are low-level structures, as DOM is intended to be language neutral, | The data structures referred to from the tree produced by a DOM parser are low-level structures, as DOM is intended to be language neutral, and not oriented towards objects. It is the difference in what constitutes a "node" in the data hierarchy that primarily accounts for the differences in programming with these APIs. | ||
==Validation== | ==Validation== |
Revision as of 18:18, 10 November 2016
Internal
Overview
The JAXP DOM API is defined by W3C. The parsers implementing the DOM API translates an entire XML document into a memory tree structure, where each node contains on of the components of an XML structure. The Document tree elements are low level data structures. For higher level object structures, use JDOM or dom4j parsers instead.
Unlike an event-driver parser API, the DOM API is memory and CPU intensive.
The parsing process begins by using DocumentBuilderFactory to create a DocumentBuilder instance. The actual implementation is dictated by the value of the javax.xml.parsers.DocumentBuilderFactory system property. The DocumentBuilder produces a Document object as a result of a parse() method invocation. DOM and SAX parsers handle errors in a similar manner, the same exceptions are generated so the error handling code is virtually identical.
When to Use JAXP DOM, JDOM or dom4j?
DOM Tree Nodes as Objects
The data structures referred to from the tree produced by a DOM parser are low-level structures, as DOM is intended to be language neutral, and not oriented towards objects. It is the difference in what constitutes a "node" in the data hierarchy that primarily accounts for the differences in programming with these APIs.
Validation
The JAXP DOM implementation supports XML Schema, so documents can be validated on parsing, which is not the case with JDOM and dom4j.
Capability to Handle Mixed Content
DOM Examples
Component Packages
- javax.xml.parsers defines DocumentBuilderFactory and DocumentBuilder classes, and error types.
- org.w3c.dom defines the Document class and other DOM components.