The original DOM working drafts provided bindings for Java and ECMAScript, a standardized version of JavaScript promoted by the Europeans Computer Manufacturer Association. The Java interface caught on, but the ECMAScript version did not. Since then, the DOM implementations have been developed
by specific vendors for C, C++, PL/SQL, Python, and Perl. Currently W3C documents use the Interface Definition Language (IDL) to represent code examples using DOM node properties and methods. IDL is an abstract language from the Object Management Group (OMG) and is not portable to other languages, such as Java, VB, or JScript.The W3C defines the specifications for DOM parsing in the W3C DOM
Recommendation. the W3C DOM can be used to create XML documents, navigate DOM structures, and add, modify, or delete DOM nodes. DOM parsing can be slower than SAX parsing because DOM creates a representation of the entire document as nodes, regardless of how large the document is.However, DOM can be handy for retrieving all the data from a document, or retrieving a piece of data several times. The DOM stays resident in memory as long as the code that created the DOM representation is running.
The first Document Object Model for HTML pages was created by the Netscape
browser development team, as a standardized way to access HTML documents
from JavaScript. The original DOM shipped in 1995 with JavaScript in the Netscape 2.0 browser. Microsoft subsequently created a similar DOM for JScript, which was included in the 1996 Internet Explorer 3.0 release.
DOM creates a representation of HTML and XML documents as a tree-like hierarchy of Node objects. There is always one root node in a document. Some Node objects can have child nodes, and are referred to as branch nodes. Other nodes are standalone nodes with no children, which are commonly referred to as leaf nodes. Some nodes are colorful with fragrant essences, and are only available in the spring. These nodes are referred to as blossom nodes. I’m just kidding about the blossom nodes, but hopefully by now you get the whole “node and tree” concept, including roots, branches, and leaves. I’ll be parsing the same very simple XML document for the DOM and SAX examples. Aside from being easy to follow, the very simple XML document in Listing 15-1 is also a generalized example of the type of document that is practical for DOM parsing. The document is so small and simple that performance will not be an issue, and I may want to reuse nodes in the document, a feature that SAX can’t provide.
Simple XML Document
<?xml version=”1.0” encoding=”UTF-8”?>
<rootelement>
<firstelement position=”1”>
<level1 children=”0”>This is level 1 of the nested elements</level1>
</firstelement>
<secondelement position=”2”>
<level1 children=”1”>
<level2>This is level two of the nested elements</level2>
</level1>
</secondelement>
</rootelement>
0 comments:
Post a Comment