JAXP DOM: Difference between revisions
Line 10: | Line 10: | ||
The JAXP DOM API is defined by W3C. The parsers implementing the DOM API translates an entire XML document into a memory tree structure. | The JAXP DOM API is defined by W3C. The parsers implementing the DOM API translates an entire XML document into a memory tree structure. | ||
The parsing process begins by using <tt>DocumentBuilderFactory</tt> to create a <tt>DocumentBuilder</tt> instance. The actual implementation is dictated by the value of the <tt>javax.xml.parsers.DocumentBuilderFactory</tt> system property. The <tt>DocumentBuilder</tt> produces a <tt>Document</tt> object as a result of a <tt>parse()</tt> method invocation. | The parsing process begins by using <tt>DocumentBuilderFactory</tt> to create a <tt>DocumentBuilder</tt> instance. The actual implementation is dictated by the value of the <tt>javax.xml.parsers.DocumentBuilderFactory</tt> system property. The <tt>DocumentBuilder</tt> produces a <tt>Document</tt> object as a result of a <tt>parse()</tt> method invocation. DOM and [[JAXP SAX|SAX]] parsers handle errors in a similar manner, the same exceptions are generated so the error handling code is virtually identical. | ||
Unlike an event-driver parser API, the DOM API is memory and CPU intensive. | Unlike an event-driver parser API, the DOM API is memory and CPU intensive. |
Revision as of 21:03, 9 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.
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.
Unlike an event-driver parser API, the DOM API is memory and CPU intensive.
The Document tree elements are low level data structures. For higher level object structures, use JDOM or dom4j parsers instead.
DOM Example
Component Packages
- javax.xml.parsers defines DocumentBuilderFactory and DocumentBuilder classes, and error types.
- org.w3c.dom defines the Document class and other DOM components.