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

  1. The docType attribute contains the Document Type Declaration associated with this document.
  2. For HTML documents or XML documents without a Document Type Declaration, the docType attribute returns null.
  3. The implementation attribute contains the DOMImplementation object that handles this document.
  4. The documentElement attribute provides direct access to the child node that is the root element of the document.
  5. For HTML documents the documentElement attributes returns the element with the "HTML" tag.
  6. Methods

  7. The createElement(tagName) method creates an element of the type specified.
  8. The tagName parameter in the createElement(tagName) method is case-sensitive for XML.
  9. The createDocumentFragment() method creates an empty DocumentFragment object.
  10. The createTextNode(data) method creates a Text node given by the specified string.
  11. The createComment(data) method creates a comment node given by the specified string.
  12. The createCDATASection(data) method creates a new CDATASection node whose value is the specified string.
  13. The createProcessingInstruction(target,data) method creates a ProcessingInstruction node given the specified name and data strings.
  14. The createAttribute(name) method creates an Attr node of the given name.
  15. The createEntityReference(name) method creates an Entity Reference object.
  16. The getElementsByTagName(tagName) method returns a NodeList of all the Elements with the given tag name.
  17. 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.
  18. The getElementsByTagName(tagName) method may use the special value "*" to match all the tags in the document tree.
  19. Exceptions

  20. The createElement(tagName) method raises an INVALID_CHARACTER_ERR DOMException if the specified name contains an invalid character.
  21. The createAttribute(name) method raises an INVALID_CHARACTER_ERR DOMException if the specified name contains an invalid character.
  22. The createEntityReference(name) method raises an INVALID_CHARACTER_ERR DOMException if the specified name contains an invalid character.
  23. The createProcessingInstruction(target,data) method raises an INVALID_CHARACTER_ERR DOMException if an invalid character was specified.
  24. The createCDATASection(data) method raises a NOT_SUPPORTED_ERR DOMException if this document is an HTML document.
  25. The createProcessingInstruction(data)method raises a NOT_SUPPORTED_ERR DOMException if this document is an HTML document.
  26. 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