Node Interface

The Node interface is the primary datatype for the entire Document Object Model. It represents a single node in the document tree.



IDL Definition

Interface Node {

         // NodeType
         const unsigned short       ELEMENT_NODE       = 1;
         const unsigned short       ATTRIBUTE_NODE     = 2;
         const unsigned short       TEXT_NODE          = 3;
         const unsigned short       CDATA_SECTION_NODE = 4;
         const unsigned short       ENTITY_REFERENCE_NODE = 5;
         const unsigned short       ENTITY_NODE        = 6;
         const unsigned short       PROCESSING_INSTRUCTION_NODE = 7;
         const unsigned short       COMMENT_NODE        = 8;
         const unsigned short       DOCUMENT_NODE       = 9;
         const unsigned short       DOCUMENT_TYPE_NODE  = 10
         const unsigned short       DOCUMENT_FRAGMENT_NODE = 11;
         const unsigned short       NOTATION_NODE       = 12;
         
         readonly attribute DOMString              nodeName;
                  attribute DOMString              nodeValue;
                                     // raises (DOMException) on setting
                                     // raises (DOMException) on retreival
         readonly attribute unsigned short         nodeType;
         readonly attribute Node                   parentNode;
         readonly attribute Node                   childNodes;
         readonly attribute Node                   firstChild;
         readonly attribute Node                   lastChild;
         readonly attribute Node                   previousSibling;
         readonly attribute Node                   nextSibling;
         readonly attribute NamedNodeMap           attributes;
         readonly attribute Document                   ownerDocument;
         Node                     insertBefore(in Node newChild,
                                               in Node refChild)
                                               raises(DOMException);
         Node                     replaceChild(in None newChild,
                                               in Node oldChild)
                                               raises(DOMException);
         Node                     remove Child(in Node oldChild)
                                               raises(DOMException); 
         Node                     appendChild(in Node newChild)
                                              raises(DOMException);
         boolean                  hasChildNodes();
         Node                     cloneNode(in boolean deep); 
}

Semantic Requirements

    Definition group

  1. The predefined nodeType integer constant for an Element node is 1 (ELEMENT_NODE).
  2. The predefined nodeType integer constant for an Attribute node is 2 (ATTRIBUTE_NODE).
  3. The predefined nodeType integer constant for a Text node is 3 (TEXT_NODE).
  4. The predefined nodeType integer constant for a CDATASection node is 4 (CDATA_SECTION_NODE).
  5. The predefined nodeType integer constant for an EntityReference node is 5 (ENTITY_REFERENCE_NODE).
  6. The predefined nodeType integer constant for an Entity node is 6 (ENTITY_NODE).
  7. The predefined nodeType integer constant for a ProcessingInstruction node is 7 (PROCESSING_INSTRUCTION_NODE).
  8. The predefined nodeType integer constant for a Comment node is 8 (COMMENT_NODE).
  9. The predefined nodeType integer constant for a Document node is 9 (DOCUMENT_NODE).
  10. The predefined nodeType integer constant for a DocumentType node is 10 (DOCUMENT_TYPE_NODE).
  11. The predefined nodeType integer constant for a DocumentFragment node is 11 (DOCUMENT_FRAGMENT_NODE).
  12. The predefined nodeType integer constant for a Notation node is 12 (NOTATION_NODE).
  13. The values of nodeName, nodeValue and attributes vary according to the node type as follows:
  14. nodeName NodeValue attributes
    Element tagName null namedNodeMap
    Attr name of attribute value of attribute null
    Text #text context of text node null
    CDATASection #cdata-section content of CDATA Section null
    EntityReference name of entity referenced null null
    Entity entity name null null
    ProcessingInstruction target entire content excluding the target null
    Comment #comment content of the comment null
    Document #document null null
    DocumentType document type name null null
    DocumentFragment #document-fragment null null
    Notation notation name null null

    Attributes

  15. The nodeType attribute contains a code representing the type of the underlying object.
  16. The nodeName attribute contains the name of this node, depending on its type (see table above).
  17. The nodeValue attribute contains the value of this node, depending on its type (see table above).
  18. The attributes attribute contains a NamedNodeMap containing the attributes of this node (if it is an Element).
  19. The parentNode attribute contains the parent of this node.
  20. If a node has just been created and not yet added to the tree then its parentNode attribute has a null value.
  21. If a node has been removed from the tree then its parentNode attribute has a null value.
  22. The childNodes attribute contains a NodeList of all children of this node.
  23. If there are no children then the NodeList contained in the childNodes attribute has no nodes.
  24. Changes in the children of the node are immediately reflected in the NodeList returned by the childNodes attribute.
  25. The firstChild attribute contains the first child of this node.
  26. If there is no first child then the firstChild attribute returns null.
  27. The lastChild attribute returns the last child of this node.
  28. If there is no last child then the lastChild attribute returns null.
  29. The previousSibling attribute returns the node immediately preceding this node.
  30. If there is no node immediately preceding this node then the previousSibling attribute returns null.
  31. The nextSibling attribute contains the node immediately following this node.
  32. If there is no node immediately following this node then the nextSibling attribute returns null.
  33. The ownerDocument attribute contains the Document object associated with this node.
  34. When this node is a Document then the ownerDocument attribute returns null.
  35. Methods

  36. The insertBefore(newChild,refChild) method inserts the node newChild before the existing child refChild.
  37. If refChild is null then the insertBefore(newChild,refChild) method inserts the newChild at the end of the list of children.
  38. If newChild is a DocumentFragment object, all of its children are inserted in the same order.
  39. The insertBefore(newChild,refChild) method returns the node being inserted.
  40. If newChild is already in the tree, the insertBefore(newChild,refChild) method first remove it before the insertion.
  41. The replaceChild(newChild,oldChild) method replaces the child node oldChild with newChild in the list of children.
  42. if the newChild is already in the list then the replaceChild(newChild,oldChild) method first remove the already existing newChild node.
  43. The replaceChild(newChild,oldChild) method returns the node replaced.
  44. The removeChild(oldChild) method removes the node indicated by oldChild.
  45. The removeChild(oldChild) method returns the node removed.
  46. The appendChild(newChild) method adds the node newChild to the end of the list of children of this node.
  47. if the newChild is already in the list then the appendChild(newCh ild) method first remove the already existing newChild node.
  48. If newChild (from the appendChild(newChild) method) is a DocumentFragment object then the entire contents of the document fragment is moved into the child list of this node.
  49. The appendChild(newChild) method returns the node added.
  50. The hasChildNodes() method returns true if the node has any children.
  51. The hasChildNodes() method returns false if the node has no children.
  52. The cloneNode(deep) method returns a duplicate of the node only if deep = false.
  53. The cloneNode(deep) method returns a duplicate of the node and the subtree under it if deep = true.
  54. The node returned by the cloneNode(deep) method has no parent.
  55. The cloneNode(deep) method does not copy any text unless it is deep clone.
  56. If the cloneNode(deep) method was used to clone an Element then all attributes and their values are copied.
  57. DOMExceptions

  58. The nodeValue attribute raises a NO_MODIFICATION_ALLOWED_ERR DOMException when the node is readonly.
  59. The insertBefore(newChild,refChild) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException when the node is readonly.
  60. The replaceChild(newChild,oldChild) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException when the node is readonly.
  61. The removeChild(oldChild) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException when the node is readonly.
  62. The appendChild(newChild) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException when the node is readonly.
  63. The insertBefore(newChild,refChild) method raises a HIERARCHY_REQUEST_ERR DOMException if this node does not allow children of the type of the newChild node.
  64. The insertBefore(newChild,refChild) method raises a HIERARCHY_REQUEST_ERR DOMException if the node to insert is one of this node's ancestors.
  65. The replaceChild(newChild,oldChild) method raises a HIERARCHY_REQUEST_ERR DOMException if this node does not allow children of the type of newChild node.
  66. The replaceChild(newChild,oldChild) method raises a HIERARCHY_REQUEST_ERR DOMException if the node to put in is one of this node's ancestors.
  67. The appendChild(newChild) method raises a HIERARCHY_REQUEST_ERR DOMException if this node does not allow children of the type of the newChild node.
  68. The appendChild(newChild,oldChild) method raises a HIERARCHY_REQUEST_ERR DOMException if the node to append is one of this node's ancestors.
  69. The insertBefore(newChild,refChild) method raises a NOT_FOUND_ERR DOMException if refChild is not a child of this node.
  70. The replaceChild(newChild,oldChild) method raises a NOT_FOUND_ERR DOMException if oldChild is not a child of this node.
  71. The and removeChild(oldChild) method raises a NOT_FOUND_ERR DOMException if oldChild is not a child of this node.
  72. The insertBefore(newChild,refChild) method raises a WRONG_DOCUMENT_ERR DOMException if newChild was created from a different document that the one that created this node.
  73. The replaceChild(newChild,oldChild) method raises a WRONG_DOCUMENT_ERR DOMException if newChild was created from a different document that the one that created this node.
  74. The appendChild(newChild) method raises a WRONG_DOCUMENT_ERR DOMexception if newChild was created from a different document that the one that created this node.

If you have comments or suggestions, email me at mbrady@nist.gov