class DOM_Element : public DOM_Node

By far the vast majority of objects (apart from text) that authors encounter when traversing a document are DOM_Element nodes

Inheritance:


Public

Constructors and assignment operator
DOM_Element ()
Default constructor for DOM_Element
DOM_Element (const DOM_Element &other)
Copy constructor
DOM_Element& operator = (const DOM_Element &other)
Assignment operator
DOM_Element& operator = (const DOM_NullPtr *val)
Assignment operator
Destructor.
~DOM_Element ()
Destructor
Functions introduced in DOM Level 2.
DOMString getAttributeNS (const DOMString &namespaceURI, const DOMString &localName) const
Retrieves an attribute value by local name and namespace URI
void setAttributeNS (const DOMString &namespaceURI, const DOMString &qualifiedName, const DOMString &value)
Adds a new attribute
void removeAttributeNS (const DOMString &namespaceURI, const DOMString &localName)
Removes an attribute by local name and namespace URI
DOM_Attr getAttributeNodeNS (const DOMString &namespaceURI, const DOMString &localName) const
Retrieves an DOM_Attr node by local name and namespace URI
DOM_Attr setAttributeNodeNS (DOM_Attr newAttr)
Adds a new attribute
DOM_NodeList getElementsByTagNameNS (const DOMString &namespaceURI, const DOMString &localName) const
Returns a DOM_NodeList of all the DOM_Elements with a given local name and namespace URI in the order in which they would be encountered in a preorder traversal of the DOM_Document tree, starting from this node
Functions which modify the Element.
DOM_Attr removeAttributeNode (DOM_Attr oldAttr)
Removes the specified attribute
void normalize ()
Puts all Text nodes in the full depth of the sub-tree underneath this DOM_Element into a "normal" form
void removeAttribute (const DOMString &name)
Removes an attribute by name
Getter functions.
DOMString getTagName () const
The name of the element
DOMString getAttribute (const DOMString &name) const
Retrieves an attribute value by name
DOM_Attr getAttributeNode (const DOMString &name) const
Retrieves an DOM_Attr node by name
DOM_NodeList getElementsByTagName (const DOMString &name) const
Returns a NodeList of all descendant elements with a given tag name, in the order in which they would be encountered in a preorder traversal of the DOM_Element tree
Set functions.
void setAttribute (const DOMString &name, const DOMString &value)
Adds a new attribute
DOM_Attr setAttributeNode (DOM_Attr newAttr)
Adds a new attribute

Inherited from DOM_Node:

Public

Cloning function.

DOM_Node cloneNode(bool deep) const
Returns a duplicate of this node

Constructors and assignment operators

DOM_Node()
Default constructor for DOM_Node
DOM_Node(const DOM_Node &other)
Copy constructor
DOM_Node& operator = (const DOM_Node &other)
Assignment operator
DOM_Node& operator = (const DOM_NullPtr *val)
Assignment operator

Equality and Inequality operators.

bool operator == (const DOM_Node & other) const
The equality operator
bool operator == (const DOM_NullPtr *other) const
Compare with a pointer
bool operator != (const DOM_Node & other) const
The inequality operator
bool operator != (const DOM_NullPtr * other) const
Compare with a pointer

Functions to modify the DOM Node.

DOM_Node insertBefore(const DOM_Node &newChild, const DOM_Node &refChild)
Inserts the node newChild before the existing child node refChild
DOM_Node replaceChild(const DOM_Node &newChild, const DOM_Node &oldChild)
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node
DOM_Node removeChild(const DOM_Node &oldChild)
Removes the child node indicated by oldChild from the list of children, and returns it
DOM_Node appendChild(const DOM_Node &newChild)
Adds the node newChild to the end of the list of children of this node

Get functions.

DOMString getNodeName() const
The name of this node, depending on its type; see the table above
DOMString getNodeValue() const
Gets the value of this node, depending on its type
short getNodeType() const
An enum value representing the type of the underlying object
DOM_Node getParentNode() const
Gets the parent of this node
DOM_NodeList getChildNodes() const
Gets a NodeList that contains all children of this node
DOM_Node getFirstChild() const
Gets the first child of this node
DOM_Node getLastChild() const
Gets the last child of this node
DOM_Node getPreviousSibling() const
Gets the node immediately preceding this node
DOM_Node getNextSibling() const
Gets the node immediately following this node
DOM_NamedNodeMap getAttributes() const
Gets a NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise
DOM_Document getOwnerDocument() const
Gets the Document object associated with this node
void* getUserData() const
Return the user data pointer

Query functions.

bool hasChildNodes() const
This is a convenience method to allow easy determination of whether a node has any children
bool isNull() const
Test whether this node is null

Documentation

By far the vast majority of objects (apart from text) that authors encounter when traversing a document are DOM_Element nodes. Assume the following XML document:<elementExample id="demo"> <subelement1/> <subelement2><subsubelement/></subelement2> </elementExample>

When represented using DOM, the top node is an DOM_Element node for "elementExample", which contains two child DOM_Element nodes, one for "subelement1" and one for "subelement2". "subelement1" contains no child nodes.

Elements may have attributes associated with them; since the DOM_Element interface inherits from DOM_Node, the generic DOM_Node interface method getAttributes may be used to retrieve the set of all attributes for an element. There are methods on the DOM_Element interface to retrieve either an DOM_Attr object by name or an attribute value by name. In XML, where an attribute value may contain entity references, an DOM_Attr object should be retrieved to examine the possibly fairly complex sub-tree representing the attribute value. On the other hand, in HTML, where all attributes have simple string values, methods to directly access an attribute value can safely be used as a convenience.

Constructors and assignment operator

DOM_Element()
Default constructor for DOM_Element. The resulting object does not refer to an actual Element node; it will compare == to 0, and is similar to a null object reference variable in Java. It may subsequently be assigned to refer to an actual Element node.

New comment nodes are created by DOM_Document::createElement().

DOM_Element(const DOM_Element &other)
Copy constructor. Creates a new DOM_Element that refers to the same underlying actual element as the original.
Parameters:
other - The object to be copied

DOM_Element& operator = (const DOM_Element &other)
Assignment operator.
Parameters:
other - The object to be copied.

DOM_Element& operator = (const DOM_NullPtr *val)
Assignment operator. This overloaded variant is provided for the sole purpose of setting a DOM_Node reference variable to zero. Nulling out a reference variable in this way will decrement the reference count on the underlying Node object that the variable formerly referenced. This effect is normally obtained when reference variable goes out of scope, but zeroing them can be useful for global instances, or for local instances that will remain in scope for an extended time, when the storage belonging to the underlying node needs to be reclaimed.
Parameters:
val. - Only a value of 0, or null, is allowed.

Destructor.

~DOM_Element()
Destructor. The object being destroyed is the reference object, not the underlying Element itself.

Getter functions.

DOMString getTagName() const
The name of the element. For example, in: <elementExample id="demo"> ... </elementExample> , tagName has the value "elementExample". Note that this is case-preserving in XML, as are all of the operations of the DOM.

DOMString getAttribute(const DOMString &name) const
Retrieves an attribute value by name.
Returns:
The DOM_Attr value as a string, or the empty string if that attribute does not have a specified or default value.
Parameters:
name - The name of the attribute to retrieve.

DOM_Attr getAttributeNode(const DOMString &name) const
Retrieves an DOM_Attr node by name.
Returns:
The DOM_Attr node with the specified attribute name or null if there is no such attribute.
Parameters:
name - The name of the attribute to retrieve.

DOM_NodeList getElementsByTagName(const DOMString &name) const
Returns a NodeList of all descendant elements with a given tag name, in the order in which they would be encountered in a preorder traversal of the DOM_Element tree.
Returns:
A list of matching DOM_Element nodes.
Parameters:
name - The name of the tag to match on. The special value "*" matches all tags.

Set functions.

void setAttribute(const DOMString &name, const DOMString &value)
Adds a new attribute. If an attribute with that name is already present in the element, its value is changed to be that of the value parameter. This value is a simple string, it is not parsed as it is being set. So any markup (such as syntax to be recognized as an entity reference) is treated as literal text, and needs to be appropriately escaped by the implementation when it is written out. In order to assign an attribute value that contains entity references, the user must create an DOM_Attr node plus any Text and EntityReference nodes, build the appropriate subtree, and use setAttributeNode to assign it as the value of an attribute.
Throws:
DOMException INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Parameters:
name - The name of the attribute to create or alter.
value - Value to set in string form.

DOM_Attr setAttributeNode(DOM_Attr newAttr)
Adds a new attribute. If an attribute with that name is already present in the element, it is replaced by the new one.
Throws:
DOMException WRONG_DOCUMENT_ERR: Raised if newAttr was created from a different document than the one that created the element.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
INUSE_ATTRIBUTE_ERR: Raised if newAttr is already an attribute of another DOM_Element object. The DOM user must explicitly clone DOM_Attr nodes to re-use them in other elements.
Returns:
If the newAttr attribute replaces an existing attribute with the same name, the previously existing DOM_Attr node is returned, otherwise null is returned.
Parameters:
newAttr - The DOM_Attr node to add to the attribute list.

Functions which modify the Element.

DOM_Attr removeAttributeNode(DOM_Attr oldAttr)
Removes the specified attribute.
Throws:
DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised if oldAttr is not an attribute of the element.
Returns:
The DOM_Attr node that was removed.
Parameters:
oldAttr - The DOM_Attr node to remove from the attribute list. If the removed DOM_Attr has a default value it is immediately replaced.

void normalize()
Puts all Text nodes in the full depth of the sub-tree underneath this DOM_Element into a "normal" form. In the "normal" form markup (e.g., tags, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are no adjacent Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.

void removeAttribute(const DOMString &name)
Removes an attribute by name. If the removed attribute has a default value it is immediately replaced.
Throws:
DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Parameters:
name - The name of the attribute to remove.

Functions introduced in DOM Level 2.

DOMString getAttributeNS(const DOMString &namespaceURI, const DOMString &localName) const
Retrieves an attribute value by local name and namespace URI.
Returns:
The DOM_Attr value as a string, or an empty string if that attribute does not have a specified or default value.
Parameters:
namespaceURI - The namespace URI of the attribute to retrieve. When it is null or an empty string, this method behaves like getAttribute.
localName - The local name of the attribute to retrieve.

void setAttributeNS(const DOMString &namespaceURI, const DOMString &qualifiedName, const DOMString &value)
Adds a new attribute. If an attribute with the same local name and namespace URI is already present in the element, its prefix is changed to be that of the qualifiedName parameter, and its value is changed to be that of the value parameter. This value is a simple string, it is not parsed as it is being set. So any markup (such as syntax to be recognized as an entity reference) is treated as literal text, and needs to be appropriately escaped by the implementation when it is written out. In order to assign an attribute value that contains entity references, the user must create a DOM_Attr node plus any DOM_Text and DOM_EntityReference nodes, build the appropriate subtree, and use setAttributeNodeNS or setAttributeNode to assign it as the value of an attribute.
Throws:
DOMException INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Parameters:
namespaceURI - The namespace URI of the attribute to create or alter. When it is null or an empty string, this method behaves like setAttribute.
localName - The local name of the attribute to create or alter.
value - The value to set in string form.

void removeAttributeNS(const DOMString &namespaceURI, const DOMString &localName)
Removes an attribute by local name and namespace URI. If the removed attribute has a default value it is immediately replaced.
Throws:
DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Parameters:
namespaceURI - The namespace URI of the attribute to remove. When it is null or an empty string, this method behaves like removeAttribute.
localName - The local name of the attribute to remove.

DOM_Attr getAttributeNodeNS(const DOMString &namespaceURI, const DOMString &localName) const
Retrieves an DOM_Attr node by local name and namespace URI.
Returns:
The DOM_Attr node with the specified attribute local name and namespace URI or null if there is no such attribute.
Parameters:
namespaceURI - The namespace URI of the attribute to retrieve. When it is null or an empty string, this method behaves like getAttributeNode.
localName - The local name of the attribute to retrieve.

DOM_Attr setAttributeNodeNS(DOM_Attr newAttr)
Adds a new attribute. If an attribute with that local name and namespace URI is already present in the element, it is replaced by the new one.
Throws:
DOMException WRONG_DOCUMENT_ERR: Raised if newAttr was created from a different document than the one that created the element.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
INUSE_ATTRIBUTE_ERR: Raised if newAttr is already an attribute of another DOM_Element object. The DOM user must explicitly clone DOM_Attr nodes to re-use them in other elements.
Returns:
If the newAttr attribute replaces an existing attribute with the same local name and namespace URI, the previously existing DOM_Attr node is returned, otherwise null is returned.
Parameters:
newAttr - The DOM_Attr node to add to the attribute list. When the node has no namespaceURI, this method behaves like setAttributeNode.

DOM_NodeList getElementsByTagNameNS(const DOMString &namespaceURI, const DOMString &localName) const
Returns a DOM_NodeList of all the DOM_Elements with a given local name and namespace URI in the order in which they would be encountered in a preorder traversal of the DOM_Document tree, starting from this node.
Returns:
A new DOM_NodeList object containing all the matched Elements.
Parameters:
namespaceURI - The namespace URI of the elements to match on. The special value "*" matches all namespaces. When it is null or an empty string, this method behaves like getElementsByTagName.
localName - The local name of the elements to match on. The special value "*" matches all local names.


This class has no child classes.

alphabetic index hierarchy of classes


XML Parser for C++ 2.0
Copyright © IBM Corp, 1999
Center for Java Technology
10275 N. De Anza Blvd.
Cupertino CA 95014 USA
Email: xml4c@us.ibm.com

IBM Logo