clan::DomNode Class Reference - ClanLib SDK
Description: clan::DomNode Class Reference

Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
clan::DomNode Class Reference
clanXML XML

DOM Node class. More...

`#include <dom_node.h>`

Inheritance diagram for clan::DomNode:

## Public Types
enum | NodeType { NULL_NODE = 0 , ELEMENT_NODE = 1 , ATTRIBUTE_NODE = 2 , TEXT_NODE = 3 , CDATA_SECTION_NODE = 4 , ENTITY_REFERENCE_NODE = 5 , ENTITY_NODE = 6 , PROCESSING_INSTRUCTION_NODE = 7 , COMMENT_NODE = 8 , DOCUMENT_NODE = 9 , DOCUMENT_TYPE_NODE = 10 , DOCUMENT_FRAGMENT_NODE = 11 , NOTATION_NODE = 12 }
| An integer indicating which type of node this is. More...

## Public Member Functions
| DomNode ()
| DomNode (const DomNode &copy)
| Constructs a DomNode.
| ~DomNode ()
DomNode | append_child (DomNode new_child)
| Adds the node new_child to the end of the list of children of this node.
DomNode | clone_node (bool deep) const
| Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
DomString | find_namespace_uri (const DomString &qualified_name) const
| Searches the node tree upwards for the namespace URI of the given qualified name.
DomString | find_prefix (const DomString &namespace_uri) const
| Searches the node tree upwards for the prefix name for the namespace URI.
DomNamedNodeMap | get_attributes () const
| A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
DomNodeList | get_child_nodes () const
| Returns a NodeList that contains all children of this node.
DomNode | get_first_child () const
| The first child of this node.
DomNode | get_last_child () const
| The last child of this node.
DomString | get_local_name () const
| Returns local part of the qualified name of this node.
DomString | get_namespace_uri () const
| Returns the namespace URI of this node.
DomNode | get_next_sibling () const
| The node immediately following this node.
DomString | get_node_name () const
| Returns the node name.
unsigned short | get_node_type () const
| Returns the node type (one of those in the NodeType enum).
DomString | get_node_value () const
| Returns the node value.
DomDocument | get_owner_document () const
| The Document object associated with this node.
DomNode | get_parent_node () const
| Returns the parent of this node.
DomString | get_prefix () const
| Returns the namespace prefix of the node.
DomNode | get_previous_sibling () const
| The node immediately preceding this node.
bool | has_attributes () const
| Returns true if this node (if its an element) has any attributes.
bool | has_child_nodes () const
| Returns true if this node has any children.
DomNode | insert_before (DomNode &new_child, DomNode &ref_child)
| Inserts the node new_child before the existing child node ref_child.
bool | is_attr () const
| Returns true if this is an attribute node.
bool | is_cdata_section () const
| Returns true if this is a CDATA section node.
bool | is_comment () const
| Returns true if this is a comment node.
bool | is_document () const
| Returns true if this is a document node.
bool | is_document_fragment () const
| Returns true if this is a document fragment node.
bool | is_document_type () const
| Returns true if this is a document type node.
bool | is_element () const
| Returns true if this is an element node.
bool | is_entity () const
| Returns true if this is an entity node.
bool | is_entity_reference () const
| Returns true if this is an entity reference node.
bool | is_notation () const
| Returns true if this is a notation node.
bool | is_null () const
| Returns true if this is a null node.
bool | is_processing_instruction () const
| Returns true if this is a processing instruction node.
bool | is_supported (const DomString &feature, const DomString &version) const
| Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
bool | is_text () const
| Returns true if this is a text node.
DomNode | named_item (const DomString &name) const
| Returns the first child node with the specified node name.
DomNode | named_item_ns (const DomString &namespace_uri, const DomString &local_name) const
| Retrieves the first child node with the specified namespace URI and local name.
void | normalize ()
| Merges any adjacent Text nodes.
bool | operator!= (const DomNode &other) const
| Compare operator.
DomNode & | operator= (const DomNode &copy)
| Copy assignment operator.
bool | operator== (const DomNode &other) const
| Compare operator.
DomNode | remove_child (DomNode &old_child)
| Removes the child node indicated by old_child from the list of children, and returns it.
DomNode | replace_child (DomNode &new_child, DomNode &old_child)
| Replaces the child node old_child with new_child in the list of children.
bool | select_bool (const DomString &xpath_expression) const
| Returns the first node value (as boolean) matching the specified xpath expression using this node as the context node.
float | select_float (const DomString &xpath_expression) const
| Returns the first node value (as float) matching the specified xpath expression using this node as the context node.
int | select_int (const DomString &xpath_expression) const
| Returns the first node value (as integer) matching the specified xpath expression using this node as the context node.
DomNode | select_node (const DomString &xpath_expression) const
| Returns the first node matching the specified xpath expression using this node as the context node.
std::vector< DomNode > | select_nodes (const DomString &xpath_expression) const
| Returns all the nodes matching the specified xpath expression using this node as the context node.
std::string | select_string (const DomString &xpath_expression) const
| Returns the first node value matching the specified xpath expression using this node as the context node.
void | set_node_value (const DomString &value)
| Sets the node value.
void | set_prefix (const DomString &prefix)
| Sets the namespace prefix of the node.
DomAttr | to_attr () const
| Returns the Attribute interface to this node.
DomCDATASection | to_cdata_section () const
| Returns the CDATA Section interface to this node.
DomComment | to_comment () const
| Returns the Comment interface to this node.
DomDocument | to_document () const
| Returns the Document interface to this node.
DomDocumentFragment | to_document_fragment () const
| Returns the Document Fragment interface to this node.
DomDocumentType | to_document_type () const
| Returns the Document Type interface to this node.
DomElement | to_element () const
| Returns the Element interface to this node.
DomEntity | to_entity () const
| Returns the Entity interface to this node.
DomEntityReference | to_entity_reference () const
| Returns the Entity Reference interface to this node.
DomNotation | to_notation () const
| Returns the Notation interface to this node.
DomProcessingInstruction | to_processing_instruction () const
| Returns the Processing Instruction interface to this node.
DomText | to_text () const
| Returns the Text interface to this node.

## Protected Member Functions
| DomNode (const std::shared_ptr< DomNode_Impl > &impl)
| DomNode (DomDocument doc, unsigned short node_type)

## Protected Attributes
std::shared_ptr< DomNode_Impl > | impl

## Friends
class | DomDocument
class | DomNamedNodeMap

## Detailed Description

DOM Node class.

The Node 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 Node interface expose methods for dealing with children, not all objects implementing the Node interface may have children. For example, Text nodes may not have children, and adding children to such nodes results in a DOMException being thrown.

The attributes 'node_name', 'node_value' and 'attributes' 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 node_type (e.g., node_value for an Element or attributes for a Comment), this returns null. Note that the specialized interfaces may contain additional and more convenient mechanisms to get and set the relevant information.

## Member Enumeration Documentation

## ◆ NodeType

enum clan::DomNode::NodeType

An integer indicating which type of node this is.

Enumerator
NULL_NODE |
ELEMENT_NODE |
ATTRIBUTE_NODE |
TEXT_NODE |
CDATA_SECTION_NODE |
ENTITY_REFERENCE_NODE |
ENTITY_NODE |
PROCESSING_INSTRUCTION_NODE |
COMMENT_NODE |
DOCUMENT_NODE |
DOCUMENT_TYPE_NODE |
DOCUMENT_FRAGMENT_NODE |
NOTATION_NODE |

## Constructor & Destructor Documentation

## ◆ DomNode() [1/4]

clan::DomNode::DomNode | ( |  | ) |

## ◆ DomNode() [2/4]

clan::DomNode::DomNode | ( | const DomNode & | copy | ) |

Constructs a DomNode.

Parameters

  copy | = Dom Node

## ◆ ~DomNode()

clan::DomNode::~DomNode | ( |  | ) |

## ◆ DomNode() [3/4]

clan::DomNode::DomNode | ( | DomDocument | doc,
|  | unsigned short | node_type )
| protected

## ◆ DomNode() [4/4]

clan::DomNode::DomNode | ( | const std::shared_ptr< DomNode_Impl > & | impl | ) |
| protected

## Member Function Documentation

## ◆ append_child()

DomNode clan::DomNode::append_child | ( | DomNode | new_child | ) |

Adds the node new_child to the end of the list of children of this node.

If the new_child is already in the tree, it is first removed.

## ◆ clone_node()

DomNode clan::DomNode::clone_node | ( | 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.

Cloning an Element copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any text it contains unless it is a deep clone, since the text is contained in a child Text node. Cloning any other type of node simply returns a copy of this node.

Parameters

  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 Element). retval: The duplicate node.

## ◆ find_namespace_uri()

DomString clan::DomNode::find_namespace_uri | ( | const DomString & | qualified_name | ) | const

Searches the node tree upwards for the namespace URI of the given qualified name.

## ◆ find_prefix()

DomString clan::DomNode::find_prefix | ( | const DomString & | namespace_uri | ) | const

Searches the node tree upwards for the prefix name for the namespace URI.

## ◆ get_attributes()

DomNamedNodeMap clan::DomNode::get_attributes | ( |  | ) | const

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

## ◆ get_child_nodes()

DomNodeList clan::DomNode::get_child_nodes | ( |  | ) | const

Returns a NodeList that contains all children of this node.

If there are no children, this is a NodeList containing no nodes. The content of the returned NodeList is "live" in the sense that, for instance, changes to the children of the node object that it was created from are immediately reflected in the nodes returned by the NodeList accessors; it is not a static snapshot of the content of the node. This is true for every NodeList, including the ones returned by the getElementsByTagName method.

## ◆ get_first_child()

DomNode clan::DomNode::get_first_child | ( |  | ) | const

The first child of this node.

If there is no such node, this returns a null node.

## ◆ get_last_child()

DomNode clan::DomNode::get_last_child | ( |  | ) | const

The last child of this node.

If there is no such node, this returns a null node.

## ◆ get_local_name()

DomString clan::DomNode::get_local_name | ( |  | ) | const

Returns local part of the qualified name of this node.

For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as create_element from the Document interface, this is always an empty string.

## ◆ get_namespace_uri()

DomString clan::DomNode::get_namespace_uri | ( |  | ) | const

Returns the namespace URI of this node.

## ◆ get_next_sibling()

DomNode clan::DomNode::get_next_sibling | ( |  | ) | const

The node immediately following this node.

If there is no such node, this returns a null node.

## ◆ get_node_name()

DomString clan::DomNode::get_node_name | ( |  | ) | const

Returns the node name.

The return value vary according to the node type as follows:

- Element: name of tag
- Attr: name of attribute
- Text: "#text"
- CDataSection: "#cdata-section"
- EntityReference: name of entity referenced
- Entity: entity name
- ProcessingInstruction: target
- Comment: "#comment"
- Document: "#document"
- DocumentType: document type name
- DocumentFragment: "#document-fragment"
- Notation: notation name

## ◆ get_node_type()

unsigned short clan::DomNode::get_node_type | ( |  | ) | const

Returns the node type (one of those in the NodeType enum).

## ◆ get_node_value()

DomString clan::DomNode::get_node_value | ( |  | ) | const

Returns the node value.

The return value vary according to the node type as follows:

- Element: null
- Attr: value of attribute
- Text: content of text node
- CDataSection: content of CDATA Section
- EntityReference: null
- Entity: null
- ProcessingInstruction: entire content excluding the target
- Comment: content of the comment
- Document: null
- DocumentType: null
- DocumentFragment: null
- Notation: null

## ◆ get_owner_document()

DomDocument clan::DomNode::get_owner_document | ( |  | ) | const

The Document object associated with this node.

This is also the Document object used to create new nodes. When this node is a Document this is null.

## ◆ get_parent_node()

DomNode clan::DomNode::get_parent_node | ( |  | ) | const

Returns the parent of this node.

All nodes, except Document, DocumentFragment, and Attr 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.

## ◆ get_prefix()

DomString clan::DomNode::get_prefix | ( |  | ) | const

Returns the namespace prefix of the node.

For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as create_element from the Document interface, this is always an empty string.

## ◆ get_previous_sibling()

DomNode clan::DomNode::get_previous_sibling | ( |  | ) | const

The node immediately preceding this node.

If there is no such node, this returns a null node.

## ◆ has_attributes()

bool clan::DomNode::has_attributes | ( |  | ) | const

Returns true if this node (if its an element) has any attributes.

## ◆ has_child_nodes()

bool clan::DomNode::has_child_nodes | ( |  | ) | const

Returns true if this node has any children.

## ◆ insert_before()

DomNode clan::DomNode::insert_before | ( | DomNode & | new_child,
|  | DomNode & | ref_child )

Inserts the node new_child before the existing child node ref_child.

If refChild is a null node, inserts new_child at the end of the list of children.

If newChild is a DocumentFragment object, all of its children are inserted, in the same order, before ref_child. If the new_child is already in the tree, it is first removed.

Parameters

  new_child | The node to insert.
  ref_child | The reference node, i.e., the node before which the new node must be inserted. retval: The node being inserted.

## ◆ is_attr()

bool clan::DomNode::is_attr | ( |  | ) | const

Returns true if this is an attribute node.

## ◆ is_cdata_section()

bool clan::DomNode::is_cdata_section | ( |  | ) | const

Returns true if this is a CDATA section node.

## ◆ is_comment()

bool clan::DomNode::is_comment | ( |  | ) | const

Returns true if this is a comment node.

## ◆ is_document()

bool clan::DomNode::is_document | ( |  | ) | const

Returns true if this is a document node.

## ◆ is_document_fragment()

bool clan::DomNode::is_document_fragment | ( |  | ) | const

Returns true if this is a document fragment node.

## ◆ is_document_type()

bool clan::DomNode::is_document_type | ( |  | ) | const

Returns true if this is a document type node.

## ◆ is_element()

bool clan::DomNode::is_element | ( |  | ) | const

Returns true if this is an element node.

## ◆ is_entity()

bool clan::DomNode::is_entity | ( |  | ) | const

Returns true if this is an entity node.

## ◆ is_entity_reference()

bool clan::DomNode::is_entity_reference | ( |  | ) | const

Returns true if this is an entity reference node.

## ◆ is_notation()

bool clan::DomNode::is_notation | ( |  | ) | const

Returns true if this is a notation node.

## ◆ is_null()

bool clan::DomNode::is_null | ( |  | ) | const

Returns true if this is a null node.

## ◆ is_processing_instruction()

bool clan::DomNode::is_processing_instruction | ( |  | ) | const

Returns true if this is a processing instruction node.

## ◆ is_supported()

bool clan::DomNode::is_supported | ( | const DomString & | feature,
|  | const DomString & | version ) const

Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.

## ◆ is_text()

bool clan::DomNode::is_text | ( |  | ) | const

Returns true if this is a text node.

## ◆ named_item()

DomNode clan::DomNode::named_item | ( | const DomString & | name | ) | const

Returns the first child node with the specified node name.

Returns a null node if no child is found.

## ◆ named_item_ns()

DomNode clan::DomNode::named_item_ns | ( | const DomString & | namespace_uri,
|  | const DomString & | local_name ) const

Retrieves the first child node with the specified namespace URI and local name.

## ◆ normalize()

void clan::DomNode::normalize | ( |  | ) |

Merges any adjacent Text nodes.

Puts all Text 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 lookups) that depend on a particular document tree structure are to be used.

Note: In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.

## ◆ operator!=()

bool clan::DomNode::operator!= | ( | const DomNode & | other | ) | const

Compare operator.

## ◆ operator=()

DomNode & clan::DomNode::operator= | ( | const DomNode & | copy | ) |

Copy assignment operator.

All objects in the DOM are handles to the underlying implementation. Therefore this doesn't actually copy contents between two DomNode's, but instead change the two DomNode's to point at the same node in the DOM.

## ◆ operator==()

bool clan::DomNode::operator== | ( | const DomNode & | other | ) | const

Compare operator.

## ◆ remove_child()

DomNode clan::DomNode::remove_child | ( | DomNode & | old_child | ) |

Removes the child node indicated by old_child from the list of children, and returns it.

## ◆ replace_child()

DomNode clan::DomNode::replace_child | ( | DomNode & | new_child,
|  | DomNode & | old_child )

Replaces the child node old_child with new_child in the list of children.

If the new_child is already in the tree, it is first removed.

Parameters

  new_child | The new node to put in the child list.
  old_child | The node being replaced in the list. retval: The node replaced.

## ◆ select_bool()

bool clan::DomNode::select_bool | ( | const DomString & | xpath_expression | ) | const

Returns the first node value (as boolean) matching the specified xpath expression using this node as the context node.

## ◆ select_float()

float clan::DomNode::select_float | ( | const DomString & | xpath_expression | ) | const

Returns the first node value (as float) matching the specified xpath expression using this node as the context node.

## ◆ select_int()

int clan::DomNode::select_int | ( | const DomString & | xpath_expression | ) | const

Returns the first node value (as integer) matching the specified xpath expression using this node as the context node.

## ◆ select_node()

DomNode clan::DomNode::select_node | ( | const DomString & | xpath_expression | ) | const

Returns the first node matching the specified xpath expression using this node as the context node.

## ◆ select_nodes()

std::vector< DomNode > clan::DomNode::select_nodes | ( | const DomString & | xpath_expression | ) | const

Returns all the nodes matching the specified xpath expression using this node as the context node.

## ◆ select_string()

std::string clan::DomNode::select_string | ( | const DomString & | xpath_expression | ) | const

Returns the first node value matching the specified xpath expression using this node as the context node.

## ◆ set_node_value()

void clan::DomNode::set_node_value | ( | const DomString & | value | ) |

Sets the node value.

## ◆ set_prefix()

void clan::DomNode::set_prefix | ( | const DomString & | prefix | ) |

Sets the namespace prefix of the node.

Note that setting this attribute, when permitted, changes the node_name attribute, which holds the qualified name, as well as the tag_name and name attributes of the Element and Attr interfaces, when applicable.

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 namespace_uri and local_name do not change.

## ◆ to_attr()

DomAttr clan::DomNode::to_attr | ( |  | ) | const

Returns the Attribute interface to this node.

If the node is not an Attribute node, then it returns a null node.

## ◆ to_cdata_section()

DomCDATASection clan::DomNode::to_cdata_section | ( |  | ) | const

Returns the CDATA Section interface to this node.

If the node is not a CDATA Section node, then it returns a null node.

## ◆ to_comment()

DomComment clan::DomNode::to_comment | ( |  | ) | const

Returns the Comment interface to this node.

If the node is not a Comment node, then it returns a null node.

## ◆ to_document()

DomDocument clan::DomNode::to_document | ( |  | ) | const

Returns the Document interface to this node.

If the node is not a Document node, then it returns a null node.

## ◆ to_document_fragment()

DomDocumentFragment clan::DomNode::to_document_fragment | ( |  | ) | const

Returns the Document Fragment interface to this node.

If the node is not a DocumentFragment node, then it returns a null node.

## ◆ to_document_type()

DomDocumentType clan::DomNode::to_document_type | ( |  | ) | const

Returns the Document Type interface to this node.

If the node is not a Document Type node, then it returns a null node.

## ◆ to_element()

DomElement clan::DomNode::to_element | ( |  | ) | const

Returns the Element interface to this node.

If the node is not an Element node, then it returns a null node.

## ◆ to_entity()

DomEntity clan::DomNode::to_entity | ( |  | ) | const

Returns the Entity interface to this node.

If the node is not an Entity node, then it returns a null node.

## ◆ to_entity_reference()

DomEntityReference clan::DomNode::to_entity_reference | ( |  | ) | const

Returns the Entity Reference interface to this node.

If the node is not an Entity Reference node, then it returns a null node.

## ◆ to_notation()

DomNotation clan::DomNode::to_notation | ( |  | ) | const

Returns the Notation interface to this node.

If the node is not a Notation node, then it returns a null node.

## ◆ to_processing_instruction()

DomProcessingInstruction clan::DomNode::to_processing_instruction | ( |  | ) | const

Returns the Processing Instruction interface to this node.

If the node is not a Processing Instrucion node, then it returns a null node.

## ◆ to_text()

DomText clan::DomNode::to_text | ( |  | ) | const

Returns the Text interface to this node.

If the node is not a Text node, then it returns a null node.

## Friends And Related Symbol Documentation

## ◆ DomDocument

friend class DomDocument
| friend

## ◆ DomNamedNodeMap

friend class DomNamedNodeMap
| friend

## Member Data Documentation

## ◆ impl

std::shared_ptr<DomNode_Impl> clan::DomNode::impl
| protected

The documentation for this class was generated from the following file:

- dom_node.h