Element Interface

The Element is the most common of all interfaces. The boudaries of an Element are dilimited by a set of start end tags. Each element has a type, identified by name and may have a set of attributes.



IDL Definition

Interface Element:Node {

                 readonly  attribute  DOMString  tagName;
                 DOMString                  getAttribute(in DomString name); 
                 void                       setAttribute(in DOMString name,
                                                         in DOMString value)
                                                         raises(DOMException);
                 void                       removeAttribute(in DOMString name)
                                                            raises(DOMException);
                 Attr                       getAttributeNode(in DOMString name);
                 Attr                       setAttributeNode(in Attr newAttr)
                                                             raises(DOMException);
                 Attr                       removeAttributeNode(in Attr oldAttr)
                                                                raises(DOMException);
                 NodeList                   getElementsByTagName(in DOMString name);
                 void                       normalize();
 
};

Semantic Requirements

  1. <Element> nodes may have attributes associated with them.
  2. The generic attribute "attributes" (from the Node interface) may be used to retrieve the set of all attributes for an element.
  3. Attributes

  4. The tagName attribute contains the name of the element.
  5. Methods

  6. The getAttribute(name) method retrieves an attribute value by name.
  7. The getAttribute(name) method returns the Attr value as a string. If the attribute has no default or specified value, it will return the empty string.
  8. The setAttribute(name,value) method adds a new attribute.
  9. If an attribute is already present in the element with that name, then its value is changed to be the one of the value parameter.
  10. The removeAttribute(name) method removes an attribute by name. If the removed attribute has a default value, it is immediately replaced.
  11. The getAttributeNode(name) method retrieves an <Attr> node by name.
  12. The getAttributeNode(name) method returns the <Attr> node with the specified attribute or null if there is no such attribute.
  13. The setAttributeNode(newAttr) method adds a new attribute node.
  14. If the new attribute node to be added by the setAttributeNode(newAttr) method is already present in the element, then it is replaced by the new one.
  15. If the new <Attr> replaces an existing attribute node with the same name, then the setAttributeNode(newAttr) method returns the previously existing <Attr> node, otherwise it returns null.
  16. The removeAttributeNode(oldAttr) method removes the specified attribute node.
  17. If the removed <Attr> is known to have a default value, an attribute immediately appears containing the default value.
  18. The removeAtributeNode(oldAttr) method returns the node that was removed.
  19. The getElementsByTagName(name) method returns a NodeList of all descendant elements with a given tag name.
  20. The list of children returned by the getElementsByTagName(name) method is in the order the children were encountered in a preorder traversal of the Element tree.
  21. The getElementsByTagName(name) may use the special value of "*" instead of a name to match all the tags in the Element tree.
  22. The normalize() method puts all the Text nodes in the full depth of the sub-tree underneath this Element into a "normal" form.
  23. DOMExceptions

  24. The setAttribute(name, value) method raises an INVALID_CHARACTER_ERR DOMException if the specified name contains an invalid character.
  25. The setAttribute(name, value) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException if this node is readonly.
  26. The removeAttribute(name) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException if this node is readonly.
  27. The setAttributeNode(newAttr) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException if this node is readonly.
  28. The removeAttributeNode(name) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException if this node is readonly.
  29. The setAttributeNode(newAttr) method raises a WRONG_DOCUMENT_ERR DOMException if the new <Attr> was created from a different document than the one that created this element.
  30. The setAttributeNode(newAttr) method raises an INUSE_ATTRIBUTE_ERR DOMException if the new <Attr> is already an attribute of another Element object.
  31. The removeAttributeNode(oldAttr) method raises a NOT_FOUND_ERR DOMException if the old <Attr> is not an attribute of the element.

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