Document Interface
The Document interface represents the HTML or XML document. Conceptually it is the root of the document tree, and provides the primary access to the document's data.
IDL Definition
Interface Document : Node {
readonly attribute DocumentType doctype;
readonly attribute DOMImplementation implementation;
readonly attribute Element documentElement;
Element createElement(in DOMString tagName)
raises(DOMException);
DocumentFragment createDocumentFragment();
Text createTextNode(in DOMString data);
Comment createComment(in DOMString data);
CDATASection createCDATASection(in DOMString data)
raises(DOMException);
ProcesingInstruction createProcessingInstruction(in DOMString target,
in DOMString data)
raises(DOMException);
Attr createAttribute(in DOMString name)
raises(DOMException);
EntityReference createEntityReference(in DOMString name)
raises(DOMException);
NodeList getElementsByTagName(in DOMString tagName);
};
Semantic Requirements
- The docType attribute contains the Document Type Declaration associated with this document.
- For HTML documents or XML documents without a Document Type Declaration, the docType attribute returns null.
- The implementation attribute contains the DOMImplementation object that handles this document.
- The documentElement attribute provides direct access to the child node that is the root element of the document.
- For HTML documents the documentElement attributes returns the element with the "HTML" tag.
Methods
- The createElement(tagName) method creates an element of the type specified.
- The tagName parameter in the createElement(tagName) method is case-sensitive for XML.
- The createDocumentFragment() method creates an empty DocumentFragment object.
- The createTextNode(data) method creates a Text node given by the specified string.
- The createComment(data) method creates a comment node given by the specified string.
- The createCDATASection(data) method creates a new CDATASection node whose value is the specified string.
- The createProcessingInstruction(target,data) method creates a ProcessingInstruction node given the specified name and data strings.
- The createAttribute(name) method creates an Attr node of the given name.
- The createEntityReference(name) method creates an Entity Reference object.
- The getElementsByTagName(tagName) method returns a NodeList of all the Elements with the given tag name.
- The NodeList returned by the getElementsByTagName(tagName) method returns the list of elements in the order they were encountered in a preorder traversal of the Document tree.
- The getElementsByTagName(tagName) method may use the special value "*" to match all the tags in the document tree.
Exceptions
- The createElement(tagName) method raises an INVALID_CHARACTER_ERR DOMException if the specified name contains an invalid character.
- The createAttribute(name) method raises an INVALID_CHARACTER_ERR DOMException if the specified name contains an invalid character.
- The createEntityReference(name) method raises an INVALID_CHARACTER_ERR DOMException if the specified name contains an invalid character.
- The createProcessingInstruction(target,data) method raises an INVALID_CHARACTER_ERR DOMException if an invalid character was specified.
- The createCDATASection(data) method raises a NOT_SUPPORTED_ERR DOMException if this document is an HTML document.
- The createProcessingInstruction(data)method raises a NOT_SUPPORTED_ERR DOMException if this document is an HTML document.
- The createEntityReference(name) method raises a NOT_SUPPORTED_ERR DOMException if this document is an HTML document.
If you have comments or suggestions, email me at mbrady@nist.gov