Interface Document

Document
All Superinterfaces:
Node
All Implemented Interfaces:
Node
All Known Implementing Classes:
HTMLDocument

public Document
extends Node

The Document interface represents the entire HTML or XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.

Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a Document, the Document interface also contains the factory methods needed to create these objects. The Node objects created have a ownerDocument attribute which associates them with the Document within whose context they were created.


Field Summary
 Element documentElement
          This is a convenience attribute that allows direct access to the child node that is the root element of the document.
 
Fields inherited from class Node
childNodes, firstChild, lastChild, nextSibling, nodeName, nodeType, nodeValue, ownerDocument, parentNode, previousSibling
 
Method Summary
 Comment createComment(String data)
          Creates a Comment node given the specified string.
 Element createElement(String tagName)
          Creates an element of the type specified.
 Text createTextNode(String data)
          Creates a Text node given the specified string.
 Element getElementById(String elementId)
          Returns the Element whose ID is given by elementId.
 NodeList getElementsByTagName(String tagName)
          Returns a NodeList of all the Elements with a given tag name in the order in which they are encountered in a preorder traversal of the Document tree.
 
Methods inherited from class Node
appendChild, hasChildNodes, insertBefore, removeChild, replaceChild
 

Field Detail

documentElement

final Element documentElement
This is a convenience attribute that allows direct access to the child node that is the root element of the document. For HTML documents, this is the element with the tagName "HTML".

Method Detail

createComment

Comment createComment(String data)
Creates a Comment node given the specified string.

Parameters:
data - The data for the node.
Returns:
The new Comment object.

getElementById

Element getElementById(String elementId)
Returns the Element whose ID is given by elementId. If no such element exists, returns null. Behavior is not defined if more than one element has this ID.

Note: The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null.

Parameters:
elementId - The unique id value for an element.
Returns:
The matching element.

getElementsByTagName

NodeList getElementsByTagName(String tagName)
Returns a NodeList of all the Elements with a given tag name in the order in which they are encountered in a preorder traversal of the Document tree.

Parameters:
tagName - The name of the tag to match on. The special value "*" matches all tags.
Returns:
A new NodeList object containing all the matched Elements.

createTextNode

Text createTextNode(String data)
Creates a Text node given the specified string.

Parameters:
data - The data for the node.
Returns:
The new Text object.

createElement

Element createElement(String tagName)
Creates an element of the type specified. Note that the instance returned implements the Element interface, so attributes can be specified directly on the returned object. In addition, if there are known attributes with default values, Attr nodes representing them are automatically created and attached to the element. To create an element with a qualified name and namespace URI, use the createElementNS method.

Parameters:
tagName - The name of the element type to instantiate. For XML, this is case-sensitive. For HTML, the tagName parameter may be provided in any case, but it must be mapped to the canonical uppercase form by the DOM implementation.
Returns:
A new Element object with the nodeName attribute set to tagName, and localName, prefix, and namespaceURI set to null.