Document (Org.W3C.DOM Package)

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. .

See the following for methods.

createAttribute

Creates an Attr of the given name. Note that the Attr instance can then be set on an Element using the setAttribute method.

Syntax:

public Attr createAttribute(java.lang.String name)
                throws DOMException

Parameters:

name - The name of the attribute.

Return value:

A new Attr object.

Throws:

DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.

createCDATASection

Creates a CDATASection node whose value is the specified string.

Syntax:

public CDATASection createCDATASection(java.lang.String data)
                  throws DOMException

Parameters:

data - The data for the CDATASection contents.

Return value:

The new CDATASection object.

Throws:

DOMException - NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

createComment

Creates a Comment node given the specified string.

Syntax:

public Comment createComment(java.lang.String data)

Parameters:

data - The data for the node.

Return value:

The new Comment object.

createDocumentFragment

Creates an empty DocumentFragment object.

Syntax:

public DocumentFragment createDocumentFragment()

Return value:

A new DocumentFragment.

createElement

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.

Syntax:

public Element createElement(java.lang.String tagName)
               throws DOMException

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.

Return value:

A new Element object.

Throws:

DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.

createEntityReference

Creates an EntityReference object.

Syntax:

public EntityReference createEntityReference(java.lang.String name)
                  throws DOMException

Parameters:

name - The name of the entity to reference.

Return value:

The new EntityReference object.

Throws:

DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.

NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

createProcessingInstruction

Creates a ProcessingInstruction node given the specified name and data strings.

Syntax:

public ProcessingInstruction createProcessingInstruction(java.lang.String target, java.lang.String data)
         throws DOMException

Parameters:

target - The target part of the processing instruction.

data - The data for the node.

Return value:

The new ProcessingInstruction object.

Throws:

DOMException - INVALID_CHARACTER_ERR: Raised if an invalid character is specified.

NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

createTextNode

Creates a Text node given the specified string.

Syntax:

public Text createTextNode(java.lang.String data)

Parameters:

data - The data for the node.

Return value:

The new Text object.

getDoctype

The Document Type Declaration associated with this document. For HTML documents as well as XML documents without a document type declaration this returns null. The DOM Level 1 does not support editing the Document Type Declaration, therefore docType cannot be altered in any way

Syntax:

public DocumentType getDoctype()

getDocumentElement

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".

Syntax:

public Element getDocumentElement()

getElementsByTagName

Returns a NodeList of all the Elements with a given tag name in the order in which they would be encountered during a preorder traversal of the Document tree.

Syntax:

public NodeList getElementsByTagName(java.lang.String tagname)

Parameters:

tagname - The name of the tag to match on. The special value "*" matches all tags.

Return value:

A new NodeList object containing all the matched Elements.

getImplementation

The DOMImplementation object that handles this document. A DOM application may use objects from multiple implementations.

Syntax:

public DOMImplementation getImplementation()