#include <DomNode.h>
Inherited by xmldom::DomAttribute, xmldom::DomCharacterData, xmldom::DomDocument, xmldom::DomDocumentFragment, xmldom::DomDocumentType, xmldom::DomElement, xmldom::DomEntity, xmldom::DomEntityReference, xmldom::DomNotation, and xmldom::DomProcessingInstruction.
Inheritance diagram for xmldom::DomNode:
DomNode
interface is the primary datatype for the entire Document Object Model.
It represents a single node in the document tree. While all objects implementing the DomNode
interface expose methods for dealing with children, not all objects implementing the DomNode
interface may have children. For example, DomText
nodes may not have children, and adding children to such nodes results in a DomException
being raised.
The attributes getNodeName()
, getNodeValue()
and getAttributes()
are included as a mechanism to get at node information without casting down to the specific derived interface. In cases where there is no obvious mapping of these attributes for a specific getNodeType()
(e.g., getNodeValue()
for an DomElement
or getAttributes()
for a DomComment
), this returns null
. Note that the specialized interfaces may contain additional and more convenient mechanisms to get and set the relevant information.
The values of getNodeName()
, getNodeValue()
, and getAttributes()
vary according to the node type as follows:
Interface | getNodeName() | getNodeValue() | getAttributes() |
---|---|---|---|
DOMAttr | name of attribute | value of attribute | null |
DOMCDATASection | "#cdata-section" | content of the CDATA Section | null |
DOMComment | "#comment" | content of the comment | null |
DOMDocument | "#document" | null | null |
DOMDocumentFragment | "#document-fragment" | null | null |
DOMDocumentType | document type name | null | null |
DOMElement | tag name | null | NamedNodeMap |
DOMEntity | entity name | null | null |
DOMEntityReference | name of entity referenced | null | null |
DOMNotation | notation name | null | null |
DOMProcessingInstruction | target | entire content excluding the target | null |
DOMText | "#text" | content of the text node | null |
Public Types | |
enum | NodeType { ElementNode = 1, AttributeNode = 2, TextNode = 3, CDATASectionNode = 4, EntityReferenceNode = 5, EntityNode = 6, ProcessingInstructionNode = 7, CommentNode = 8, DocumentNode = 9, DocumentTypeNode = 10, DocumentFragmentNode = 11, NotationNode = 12, NullNode = 0 } |
An enum indicating which type of node this is. More... | |
enum | DocumentPosition { DocumentPositionDisconnected = 0x01, DocumentPositionPreceding = 0x02, DocumentPositionFollowing = 0x04, DocumentPositionContains = 0x08, DocumentPositionContainedBy = 0x10, DocumentPositionImplementationSpecific = 0x20 } |
A bitmask indicating the relative document position of a node with respect to another node. More... | |
Public Member Functions | |
DomNode () | |
Create a new "null" node. | |
DomNode (const DomNode ©) | |
copy ctor | |
virtual | ~DomNode () |
dtor | |
const DomNode & | operator= (const DomNode &assign) |
assignment | |
DOM Level 1 | |
DomString | getNodeName () const |
Get the name of this node, depending on its type. | |
DomString | getNodeValue () const |
Get the value of this node, depending on its type. | |
NodeType | getNodeType () const |
A code representing the type of the underlying object, as defined above. | |
DomNode | getParentNode () const |
The parent of this node. | |
DomNodeList | getChildNodes () const |
A DomNodeList that contains all children of this node. | |
DomNode | getFirstChild () const |
The first child of this node. | |
DomNode | getLastChild () const |
The last child of this node. | |
DomNode | getPreviousSibling () const |
The node immediately preceding this node. | |
DomNode | getNextSibling () const |
The node immediately following this node. | |
DomNamedNodeMap | getAttributes () const |
A DomNamedNodeMap containing the attributes of this node (if it is an DomElement) or null otherwise. | |
DomDocument | getOwnerDocument () const |
The DomDocument object associated with this node. | |
DomNode | cloneNode (bool deep) const |
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. | |
DomNode | insertBefore (const DomNode &newChild, const DomNode &referenceChild) |
Inserts the node newChild before the existing child node referenceChild . | |
DomNode | replaceChild (const DomNode &newChild, const DomNode &oldChild) |
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node. | |
DomNode | removeChild (const DomNode &oldChild) |
Removes the child node indicated by oldChild from the list of children, and returns it. | |
DomNode | appendChild (const DomNode &newChild) |
Adds the node newChild to the end of the list of children of this node. | |
bool | hasChildNodes () const |
Returns whether this node has any children. | |
void | setNodeValue (const DomString &nodeValue) |
Set the value of this node, depending on its type. | |
DOM Level 2 | |
void | normalize () |
Puts all DomText nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. | |
bool | isSupported (const DomString &feature, const DomString &version) const |
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node, as specified in DOM Features. | |
DomString | getNamespaceURI () const |
Get the glossaryNamespaceURI of this node, or null if it is unspecified (see xmlNamespaces). | |
DomString | getPrefix () const |
Get the glossaryNamespacePrefix of this node, or null if it is unspecified. | |
DomString | getLocalName () const |
Returns the local part of the glossaryQualifiedName of this node. | |
void | setPrefix (const DomString &prefix) |
Set the glossaryNamespacePrefix of this node. | |
bool | hasAttributes () const |
Returns whether this node (if it is an element) has any attributes. | |
DOM Level 3 | |
bool | isSameNode (const DomNode &other) const |
Returns whether this node is the same node as the given one. | |
bool | isEqualNode (const DomNode &arg) const |
Tests whether two nodes are equal. | |
DomString | getBaseURI () const |
Get the absolute base URI of this node or null if the implementation wasnt able to obtain an absolute URI. | |
DomString | getTextContent () const |
This attribute returns the text content of this node and its descendants. | |
void | setTextContent (const DomString &textContent) |
This attribute returns the text content of this node and its descendants. | |
Extensions | |
bool | isNull () const |
Check if this is a "null" node. | |
bool | isAttribute () const |
Check if this node is an attribute. | |
bool | isCDATASection () const |
Check if this node is a CDATA section. | |
bool | isComment () const |
Check if this node is a comment. | |
bool | isDocument () const |
Check if this node is a document. | |
bool | isDocumentFragment () const |
Check if this node is a document fragment. | |
bool | isDocumentType () const |
Check if this node is a document type. | |
bool | isElement () const |
Check if this node is an element. | |
bool | isEntity () const |
Check if this node is an entity. | |
bool | isEntityReference () const |
Check if this node is an entity reference. | |
bool | isNotation () const |
Check if this node is a notation. | |
bool | isProcessingInstruction () const |
Check if this node is a processing instruction. | |
DomAttribute | toAttribute () const |
Try to convert this node into an DomAttribute node. | |
DomCDATASection | toCDATASection () const |
Try to convert this node into an DomCDATASection node. | |
DomComment | toComment () const |
Try to convert this node into an DomComment node. | |
DomDocument | toDocument () const |
Try to convert this node into an DomDocument node. | |
DomDocumentFragment | toDocumentFragment () const |
Try to convert this node into an DomDocumentFragment node. | |
DomDocumentType | toDocumentType () const |
Try to convert this node into an DomDocumentType node. | |
DomElement | toElement () const |
Try to convert this node into an DomElement node. | |
DomEntity | toEntity () const |
Try to convert this node into an DomEntity node. | |
DomEntityReference | toEntityReference () const |
Try to convert this node into an DomEntityReference node. | |
DomNotation | toNotation () const |
Try to convert this node into an DomNotation node. | |
DomProcessingInstruction | toProcessingInstruction () const |
Try to convert this node into an DomProcessingInstruction node. | |
DomString | toString () const |
Serialize this node into a DomString. |
An enum indicating which type of node this is.
ElementNode |
An element node DomElement . |
AttributeNode |
An attribute node DomAttribute . |
TextNode |
A text node DomText . |
CDATASectionNode |
A CDATA section DomCDATASection . |
EntityReferenceNode |
An entity reference node DomEntityReference . |
EntityNode |
An entity node DomEntity . |
ProcessingInstructionNode |
A processing instruction node DomProcessingInstruction . |
CommentNode |
A comment node DomComment . |
DocumentNode |
A document node DomDocument . |
DocumentTypeNode |
A document type node DomDocumentType . |
DocumentFragmentNode |
A document fragment node DomDocumentFragment . |
NotationNode |
A notation node DomNotation . |
NullNode | Extension to represent a "null" node. (Not in standard). |
A bitmask indicating the relative document position of a node with respect to another node.
If the two nodes being compared are the same node, then no flags are set on the return. Otherwise, the order of two nodes is determined by looking for common containers -- containers which contain both. A node directly contains any child nodes. A node also directly contains any other nodes attached to it such as attributes contained in an element or entities and notations contained in a document type. Nodes contained in contained nodes are also contained, but less-directly as the number of intervening containers increases.
If there is no common container node, then the order is based upon order between the root container of each node that is in no container. In this case, the result is disconnected and implementation-specific. This result is stable as long as these outer-most containing nodes remain in memory and are not inserted into some other containing node. This would be the case when the nodes belong to different documents or fragments, and cloning the document or inserting a fragment might change the order.
If one of the nodes being compared contains the other node, then the container precedes the contained node, and reversely the contained node follows the container. For example, when comparing an element against its own attribute or child, the element node precedes its attribute node and its child node, which both follow it.
If neither of the previous cases apply, then there exists a most-direct container common to both nodes being compared. In this case, the order is determined based upon the two determining nodes directly contained in this most-direct common container that either are or contain the corresponding nodes being compared.
If these two determining nodes are both child nodes, then the natural DOM order of these determining nodes within the containing node is returned as the order of the corresponding nodes. This would be the case, for example, when comparing two child elements of the same element.
If one of the two determining nodes is a child node and the other is not, then the corresponding node of the child node follows the corresponding node of the non-child node. This would be the case, for example, when comparing an attribute of an element with a child element of the same element.
If neither of the two determining node is a child node and one determining node has a greater value of getNodeType() than the other, then the corresponding node precedes the other. This would be the case, for example, when comparing an entity of a document type against a notation of the same document type.
If neither of the two determining node is a child node and getNodeType() is the same for both determining nodes, then an implementation-dependent order between the determining nodes is returned. This order is stable as long as no nodes of the same getNodeType() are inserted into or removed from the direct container. This would be the case, for example, when comparing two attributes of the same element, and inserting or removing additional attributes might change the order between existing attributes.
xmldom::DomNode::DomNode | ( | ) |
Create a new "null" node.
xmldom::DomNode::DomNode | ( | const DomNode & | copy | ) |
copy ctor
xmldom::DomNode::~DomNode | ( | ) | [virtual] |
dtor
DomString xmldom::DomNode::getNodeName | ( | ) | const |
Get the name of this node, depending on its type.
See the table above.
DomString xmldom::DomNode::getNodeValue | ( | ) | const |
Get the value of this node, depending on its type.
See the table above. When it is defined to be null, setting it has no effect, including if the node is read-only.
DomNode::NodeType xmldom::DomNode::getNodeType | ( | ) | const |
A code representing the type of the underlying object, as defined above.
DomNode xmldom::DomNode::getParentNode | ( | ) | const |
The parent of this node.
All nodes, except DomAttribute, DomDocument, DomDocumentFragment, DomEntity, and DomNotation may have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null.
DomNodeList xmldom::DomNode::getChildNodes | ( | ) | const |
A DomNodeList that contains all children of this node.
If there are no children, this is a DomNodeList containing no nodes.
DomNode xmldom::DomNode::getFirstChild | ( | ) | const |
The first child of this node.
If there is no such node, this returns null.
DomNode xmldom::DomNode::getLastChild | ( | ) | const |
The last child of this node.
If there is no such node, this returns null.
DomNode xmldom::DomNode::getPreviousSibling | ( | ) | const |
The node immediately preceding this node.
If there is no such node, this returns null.
DomNode xmldom::DomNode::getNextSibling | ( | ) | const |
The node immediately following this node.
If there is no such node, this returns null.
DomNamedNodeMap xmldom::DomNode::getAttributes | ( | ) | const |
A DomNamedNodeMap containing the attributes of this node (if it is an DomElement) or null otherwise.
DomDocument xmldom::DomNode::getOwnerDocument | ( | ) | const |
The DomDocument object associated with this node.
This is also the DomDocument object used to create new nodes. When this node is a DomDocument or a DomDocumentType which is not used with any DomDocument yet, this is null.
DomNode xmldom::DomNode::cloneNode | ( | bool | deep | ) | const |
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
The duplicate node has no parent (getParentNode() is null) and no user data. User data associated to the imported node is not carried over. However, if any DomUserDataHandlers has been specified along with the associated data these handlers will be called with the appropriate parameters before this method returns.
Cloning an DomElement copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any children it contains unless it is a deep clone. This includes text contained in an the Element since the text is contained in a child DomText node.
Cloning an DomAttribute directly, as opposed to be cloned as part of an DomElement cloning operation, returns a specified attribute (specified is true). Cloning an DomAttribute always clones its children, since they represent its value, no matter whether this is a deep clone or not.
Cloning an DomEntityReference automatically constructs its subtree if a corresponding DomEntity is available, no matter whether this is a deep clone or not.
Cloning any other type of node simply returns a copy of this node.
Note that cloning an immutable subtree results in a mutable copy, but the children of an DomEntityReference clone are readonly. In addition, clones of unspecified DomAttributes nodes are specified. And, cloning DomDocument, DomDocumentType, DomEntity, and DomNotation nodes is implementation dependent.
deep | If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an DomElement). |
Inserts the node newChild
before the existing child node referenceChild
.
If referenceChild
is null, insert newChild
at the end of the list of children.
If newChild
is a DomDocumentFragment object, all of its children are inserted, in the same order, before referenceChild
. If the newChild
is already in the tree, it is first removed.
newChild | The node to insert. | |
referenceChild | The reference node, i.e., the node before which the new node must be inserted. |
Replaces the child node oldChild
with newChild
in the list of children, and returns the oldChild
node.
If newChild
is a DomDocumentFragment object, oldChild
is replaced by all of the DomDocumentFragment children, which are inserted in the same order. If the newChild
is already in the tree, it is first removed.
newChild | The new node to put in the child list. | |
oldChild | The node being replaced in the list. |
Removes the child node indicated by oldChild
from the list of children, and returns it.
oldChild | The node being removed. |
Adds the node newChild
to the end of the list of children of this node.
If the newChild is already in the tree, it is first removed.
newChild | The node to add. If it is a DomDocumentFragment object, the entire contents of the document fragment are moved into the child list of this node. |
bool xmldom::DomNode::hasChildNodes | ( | ) | const |
Returns whether this node has any children.
void xmldom::DomNode::setNodeValue | ( | const DomString & | nodeValue | ) |
Set the value of this node, depending on its type.
See the table above. When it is defined to be null, setting it has no effect, including if the node is read-only.
void xmldom::DomNode::normalize | ( | ) |
Puts all DomText nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty 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 [XPointer] lookups) that depend on a particular document tree structure are to be used. If the parameter "normalize-characters" of the DomConfiguration object attached to the DomNode::getOwnerDocument() is true, this method will also fully normalize the characters of the DomText nodes.
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node, as specified in DOM Features.
feature | The name of the feature to test. | |
version | This is the version number of the feature to test. |
DomString xmldom::DomNode::getNamespaceURI | ( | ) | const |
Get the glossaryNamespaceURI of this node, or null if it is unspecified (see xmlNamespaces).
This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.
For nodes of any type other than ElementNode
and AttributeNode
and nodes created with a DOM Level 1 method, such as DomDocument::createElement(), this is always null.
DomString xmldom::DomNode::getPrefix | ( | ) | const |
Get the glossaryNamespacePrefix of this node, or null if it is unspecified.
When it is defined to be null, setting it has no effect, including if the node is glossaryReadOnly.
Note that setting this attribute, when permitted, changes the nodeName attribute, which holds the glossaryQualifiedName, as well as the tagName and name attributes of the DomElement and DomAttribute interfaces, when applicable.
Setting the prefix to null makes it unspecified, setting it to an empty string is implementation dependent.
Note also that changing the prefix of an attribute that is known to have a default value, does not make a new attribute with the default value and the original prefix appear, since the getNamespaceURI() and getLocalName() do not change.
For nodes of any type other than ElementNode
and AttributeNode
and nodes created with a DOM Level 1 method, such as DomDocument::createElement() from the DomDocument interface, this is always null.
DomString xmldom::DomNode::getLocalName | ( | ) | const |
Returns the local part of the glossaryQualifiedName of this node.
For nodes of any type other than ElementNode
and AttributeNode
and nodes created with a DOM Level 1 method, such as DomDocument::createElement(), this is always null.
void xmldom::DomNode::setPrefix | ( | const DomString & | prefix | ) |
Set the glossaryNamespacePrefix of this node.
See getPrefix() for details.
bool xmldom::DomNode::hasAttributes | ( | ) | const |
Returns whether this node (if it is an element) has any attributes.
bool xmldom::DomNode::isSameNode | ( | const DomNode & | other | ) | const |
Returns whether this node is the same node as the given one.
This method provides a way to determine whether two DomNode references returned by the implementation reference the same object. When two DomNode references are references to the same object, even if through a proxy, the references may be used completely interchangeably, such that all attributes have the same values and calling the same DOM method on either reference always has exactly the same effect.
other | The node to test against. |
bool xmldom::DomNode::isEqualNode | ( | const DomNode & | arg | ) | const |
Tests whether two nodes are equal.
This method tests for equality of nodes, not sameness (i.e., whether the two nodes are references to the same object) which can be tested with isSameNode().
All nodes that are the same will also be equal, though the reverse may not be true. Two nodes are equal if and only if the following conditions are satisfied:
For two DomDocumentType nodes to be equal, the following conditions must also be satisfied:
On the other hand, the following do not affect equality: the getOwnerDocument(), getBaseURI(), and getParentNode() attributes, the specified attribute for DomAttribute nodes, the DomAttribute::getSchemaTypeInfo() attribute for DomAttribute and DomElement nodes, the DomText::isElementContentWhitespace() attribute for DomText nodes, as well as any user data or event listeners registered on the nodes.
arg | The node to compare equality with. |
DomString xmldom::DomNode::getBaseURI | ( | ) | const |
Get the absolute base URI of this node or null if the implementation wasnt able to obtain an absolute URI.
This value is computed as described in Base URIs. However, when the DomDocument supports the feature "HTML" [DOM Level 2 HTML], the base URI is computed using first the value of the href attribute of the HTML BASE element if any, and the value of the DomDocument::getDocumentURI() attribute from the DomDocument interface otherwise.
DomString xmldom::DomNode::getTextContent | ( | ) | const |
This attribute returns the text content of this node and its descendants.
When it is defined to be null, setting it has no effect. On setting, any possible children this node may have are removed and, if it the new string is not empty or null, replaced by a single DomText node containing the string this attribute is set to.
On getting, no serialization is performed, the returned string does not contain any markup. No whitespace normalization is performed and the returned string does not contain the white spaces in element content (see the attribute DomText::isElementContentWhitespace() ). Similarly, on setting, no parsing is performed either, the input string is taken as pure textual content. The string returned is made of the text content of this node depending on its type, as defined below:
Node type | Content |
---|---|
ElementNode, AttributeNode, EntityNode, EntityReferenceNode, DocumentFragmentNode | concatenation of the textContent attribute value of every child node, excluding CommentNode and ProcessingInstructionNode nodes. This is the empty string if the node has no children. |
TextNode, CDATASectionNode, CommentNode, ProcessingInstructionNode | nodeValue |
DocumentNode, DocumentTypeNode, NotationNode | null |
void xmldom::DomNode::setTextContent | ( | const DomString & | textContent | ) |
This attribute returns the text content of this node and its descendants.
See getTextContent() for details.
bool xmldom::DomNode::isNull | ( | ) | const |
Check if this is a "null" node.
bool xmldom::DomNode::isAttribute | ( | ) | const |
Check if this node is an attribute.
bool xmldom::DomNode::isCDATASection | ( | ) | const |
Check if this node is a CDATA section.
bool xmldom::DomNode::isComment | ( | ) | const |
Check if this node is a comment.
bool xmldom::DomNode::isDocument | ( | ) | const |
Check if this node is a document.
bool xmldom::DomNode::isDocumentFragment | ( | ) | const |
Check if this node is a document fragment.
bool xmldom::DomNode::isDocumentType | ( | ) | const |
Check if this node is a document type.
bool xmldom::DomNode::isElement | ( | ) | const |
Check if this node is an element.
bool xmldom::DomNode::isEntity | ( | ) | const |
Check if this node is an entity.
bool xmldom::DomNode::isEntityReference | ( | ) | const |
Check if this node is an entity reference.
bool xmldom::DomNode::isNotation | ( | ) | const |
Check if this node is a notation.
bool xmldom::DomNode::isProcessingInstruction | ( | ) | const |
Check if this node is a processing instruction.
DomAttribute xmldom::DomNode::toAttribute | ( | ) | const |
Try to convert this node into an DomAttribute node.
If the conversion failed, a "null" element is returned.
DomCDATASection xmldom::DomNode::toCDATASection | ( | ) | const |
Try to convert this node into an DomCDATASection node.
If the conversion failed, a "null" element is returned.
DomComment xmldom::DomNode::toComment | ( | ) | const |
Try to convert this node into an DomComment node.
If the conversion failed, a "null" element is returned.
DomDocument xmldom::DomNode::toDocument | ( | ) | const |
Try to convert this node into an DomDocument node.
If the conversion failed, a "null" element is returned.
DomDocumentFragment xmldom::DomNode::toDocumentFragment | ( | ) | const |
Try to convert this node into an DomDocumentFragment node.
If the conversion failed, a "null" element is returned.
DomDocumentType xmldom::DomNode::toDocumentType | ( | ) | const |
Try to convert this node into an DomDocumentType node.
If the conversion failed, a "null" element is returned.
DomElement xmldom::DomNode::toElement | ( | ) | const |
Try to convert this node into an DomElement node.
If the conversion failed, a "null" element is returned.
DomEntity xmldom::DomNode::toEntity | ( | ) | const |
Try to convert this node into an DomEntity node.
If the conversion failed, a "null" element is returned.
DomEntityReference xmldom::DomNode::toEntityReference | ( | ) | const |
Try to convert this node into an DomEntityReference node.
If the conversion failed, a "null" element is returned.
DomNotation xmldom::DomNode::toNotation | ( | ) | const |
Try to convert this node into an DomNotation node.
If the conversion failed, a "null" element is returned.
DomProcessingInstruction xmldom::DomNode::toProcessingInstruction | ( | ) | const |
Try to convert this node into an DomProcessingInstruction node.
If the conversion failed, a "null" element is returned.
DomString xmldom::DomNode::toString | ( | ) | const |
Serialize this node into a DomString.
A DomDocument is serialized into a well formed XML document. All other types of nodes are producing XML fragments, which could not be well formed XML.