Java Reference
In-Depth Information
This is where the DOM differs from the BOM quite extensively. The BOM objects have names that
relate to a specifi c part of the browser, such as the window object, or the forms and images collections.
As mentioned earlier, to be able to navigate in the web page as though it were a tree, you have to do it
abstractly. You can have no prior knowledge of the structure of the page; everything ultimately is just
a node. To move around from HTML element to HTML element, or element to attribute, you have to go
from node to node. This also means you can add, replace, or remove parts of your web page without
affecting the structure as a whole, as you're just changing nodes. This is why you have three rather
obscure-sounding objects that represent your tree structure.
I've already mentioned that the top of your tree structure is the root node, and that the root node con-
tains the XML declaration, the DTD, and the root element. Therefore you need more than just these three
objects to represent your document. In fact there are different objects to represent the different types of
nodes on the tree.
High-Level DOM Objects
Since everything in the DOM is a node, it's no wonder that nodes come in a variety of types. Is the node
an element, an attribute, or just plain text? The Node object has different objects to represent each possible
type of node. The following is a complete list of all the different node type objects that can be accessed via
the DOM. A lot of them won't concern you in this topic, because they're better suited for XML documents
and not HTML documents, but you should notice that your three main types of nodes, namely element,
attribute, and text, are all covered.
Object
Description
Document
The root node of the document
DocumentType
The DTD or schema type of the XML document
DocumentFragment
A temporary storage space for parts of the document
EntityReference
A reference to an entity in the XML document
Element
An element in the document
Attr
An attribute of an element in the document
ProcessingInstruction
A processing instruction
Comment
A comment in an XML document or HTML document
Text
Text that must form a child node of an element
CDATASection
A CDATA section within the XML document
Entity
An unparsed entity in the DTD
Notation
A notation declared within a DTD
We won't go over most of these objects in this chapter, but if you need to navigate the DOM of an XML
document, you will have to use them.
Search WWH ::




Custom Search