DOM Element class. More...
#include <dom_element.h>
Public Member Functions | |
DomElement () | |
Constructs a DOM Element handle. | |
DomElement (const std::shared_ptr< DomNode_Impl > &impl) | |
Constructs a DomElement. | |
DomElement (DomDocument &doc, const DomString &tag_name, const DomString &namespace_uri=DomString()) | |
~DomElement () | |
DomString | get_attribute (const DomString &name) const |
Returns the specified attribute. | |
DomString | get_attribute (const DomString &name, const DomString &default_value) const |
Get attribute. | |
bool | get_attribute_bool (const DomString &name, bool default_value=false) const |
Returns the boolean value of the attribute node with the given tag name. | |
bool | get_attribute_bool_ns (const DomString &namespace_uri, const DomString &local_name, bool default_value=false) const |
Returns the boolean value of the attribute node with the given local name and namespace. | |
float | get_attribute_float (const DomString &name, float default_value=0.0f) const |
Returns the floating-point value of the attribute node with the given tag name. | |
float | get_attribute_float_ns (const DomString &namespace_uri, const DomString &local_name, float default_value=0.0f) const |
Returns the floating-point value of the attribute node with the given local name and namespace. | |
int | get_attribute_int (const DomString &name, int default_value=0) const |
Returns the integer value of the attribute node with the given tag name. | |
int | get_attribute_int_ns (const DomString &namespace_uri, const DomString &local_name, int default_value=0) const |
Returns the integer value of the attribute node with the given local name and namespace. | |
DomAttr | get_attribute_node (const DomString &name) const |
Get attribute node. | |
DomAttr | get_attribute_node_ns (const DomString &namespace_uri, const DomString &local_name) const |
DomString | get_attribute_ns (const DomString &namespace_uri, const DomString &local_name) const |
Returns the specified attribute. | |
DomString | get_attribute_ns (const DomString &namespace_uri, const DomString &local_name, const DomString &default_value) const |
bool | get_child_bool (const DomString &name, bool default_value=false) const |
Returns the boolean value of the child node with the given tag name. | |
bool | get_child_bool_ns (const DomString &namespace_uri, const DomString &local_name, bool default_value=false) const |
Returns the boolean value of the child node with the given local name and namespace. | |
int | get_child_int (const DomString &name, int default_value=0) const |
Returns the integer value of the child node with the given tag name. | |
int | get_child_int_ns (const DomString &namespace_uri, const DomString &local_name, int default_value=0) const |
Returns the integer value of the child node with the given local name and namespace. | |
DomString | get_child_string (const DomString &name, const DomString &default_value=DomString()) const |
Returns the text value of the child node with the given tag name. | |
DomString | get_child_string_ns (const DomString &namespace_uri, const DomString &local_name, const DomString &default_value=DomString()) const |
Returns the text value of the child node with the given local name and namespace. | |
DomNodeList | get_elements_by_tag_name (const DomString &name) |
Returns a NodeList of all descendant elements with a given tag name. | |
DomNodeList | get_elements_by_tag_name_ns (const DomString &namespace_uri, const DomString &local_name) |
DomElement | get_first_child_element () const |
Returns the first child node that is an element node. | |
DomElement | get_next_sibling_element () const |
Returns the next sibling node that is an element node. | |
DomString | get_tag_name () const |
Returns the name of the element. | |
std::string | get_text () const |
Returns the text of all child Text nodes appended together. | |
bool | has_attribute (const DomString &name) const |
Returns true if the element has the specified attribute. | |
bool | has_attribute_ns (const DomString &namespace_uri, const DomString &local_name) const |
Returns true if the element has the specified attribute. | |
void | remove_attribute (const DomString &name) |
Removes an attribute by name. | |
void | remove_attribute_ns (const DomString &namespace_uri, const DomString &local_name) |
void | set_attribute (const DomString &name, const DomString &value) |
Adds a new attribute. | |
void | set_attribute_bool (const DomString &name, bool value) |
Sets the attribute node with the specified tag name to the given boolean value. | |
void | set_attribute_bool_ns (const DomString &namespace_uri, const DomString &qualified_name, bool value) |
Sets the attribute node with the specified qualified name and namespace to the given boolean value. | |
void | set_attribute_float (const DomString &name, float value, int num_decimal_places=6) |
Sets the attribute node with the specified tag name to the given floating-point value. | |
void | set_attribute_float_ns (const DomString &namespace_uri, const DomString &qualified_name, float value, int num_decimal_places=6) |
Sets the attribute node with the specified qualified name and namespace to the given floating-point value. | |
void | set_attribute_int (const DomString &name, int value) |
Sets the attribute node with the specified tag name to the given integer value. | |
void | set_attribute_int_ns (const DomString &namespace_uri, const DomString &qualified_name, int value) |
Sets the attribute node with the specified qualified name and namespace to the given integer value. | |
DomAttr | set_attribute_node (const DomAttr &attr) |
Set attribute node. | |
DomAttr | set_attribute_node_ns (const DomAttr &attr) |
Set attribute node ns. | |
void | set_attribute_ns (const DomString &namespace_uri, const DomString &qualified_name, const DomString &value) |
void | set_child_bool (const DomString &name, bool value) |
Sets the child node with the specified tag name to the given boolean value. | |
void | set_child_bool_ns (const DomString &namespace_uri, const DomString &qualified_name, bool value) |
Sets the child node with the specified qualified name and namespace to the given boolean value. | |
void | set_child_int (const DomString &name, int value) |
Sets the child node with the specified tag name to the given integer value. | |
void | set_child_int_ns (const DomString &namespace_uri, const DomString &qualified_name, int value) |
Sets the child node with the specified qualified name and namespace to the given integer value. | |
void | set_child_string (const DomString &name, const DomString &value) |
Sets the child node with the specified tag name to the given text value. | |
void | set_child_string_ns (const DomString &namespace_uri, const DomString &qualified_name, const DomString &value) |
Sets the child node with the specified qualified name and namespace to the given text value. | |
![]() | |
DomNode () | |
DomNode (const DomNode ©) | |
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 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. | |
Additional Inherited Members | |
![]() | |
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... | |
![]() | |
DomNode (const std::shared_ptr< DomNode_Impl > &impl) | |
DomNode (DomDocument doc, unsigned short node_type) | |
![]() | |
std::shared_ptr< DomNode_Impl > | impl |
DOM Element class.
By far the vast majority of objects (apart from text) that authors encounter when traversing a document are Element nodes. Assume the following XML document:
<elementExample id="demo"> <subelement1/> <subelement2><subsubelement/></subelement2> </elementExample/gt;
When represented using DOM, the top node is an Element node for "elementExample", which contains two child Element nodes, one for "subelement1" and one for "subelement2". "subelement1" contains no child nodes.
Elements may have attributes associated with them; since the Element interface inherits from Node, the generic Node interface method getAttributes may be used to retrieve the set of all attributes for an element. There are methods on the Element interface to retrieve either an Attr object by name or an attribute value by name. In XML, where an attribute value may contain entity references, an Attr object should be retrieved to examine the possibly fairly complex sub-tree representing the attribute value.
clan::DomElement::DomElement | ( | ) |
Constructs a DOM Element handle.
Referenced by get_first_child_element(), and get_next_sibling_element().
clan::DomElement::DomElement | ( | DomDocument & | doc, |
const DomString & | tag_name, | ||
const DomString & | namespace_uri = DomString() ) |
References clan::DomNode::DomDocument.
clan::DomElement::DomElement | ( | const std::shared_ptr< DomNode_Impl > & | impl | ) |
clan::DomElement::~DomElement | ( | ) |
Returns the specified attribute.
DomString clan::DomElement::get_attribute | ( | const DomString & | name, |
const DomString & | default_value ) const |
Get attribute.
name | = Dom String |
default_value | = Dom String |
bool clan::DomElement::get_attribute_bool | ( | const DomString & | name, |
bool | default_value = false ) const |
Returns the boolean value of the attribute node with the given tag name.
bool clan::DomElement::get_attribute_bool_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name, | ||
bool | default_value = false ) const |
Returns the boolean value of the attribute node with the given local name and namespace.
float clan::DomElement::get_attribute_float | ( | const DomString & | name, |
float | default_value = 0.0f ) const |
Returns the floating-point value of the attribute node with the given tag name.
float clan::DomElement::get_attribute_float_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name, | ||
float | default_value = 0.0f ) const |
Returns the floating-point value of the attribute node with the given local name and namespace.
int clan::DomElement::get_attribute_int | ( | const DomString & | name, |
int | default_value = 0 ) const |
Returns the integer value of the attribute node with the given tag name.
int clan::DomElement::get_attribute_int_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name, | ||
int | default_value = 0 ) const |
Returns the integer value of the attribute node with the given local name and namespace.
Get attribute node.
name | = Dom String |
DomAttr clan::DomElement::get_attribute_node_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name ) const |
DomString clan::DomElement::get_attribute_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name ) const |
Returns the specified attribute.
DomString clan::DomElement::get_attribute_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name, | ||
const DomString & | default_value ) const |
bool clan::DomElement::get_child_bool | ( | const DomString & | name, |
bool | default_value = false ) const |
Returns the boolean value of the child node with the given tag name.
Finds the first child node with the specified tag name, then returns the content of its first child text node as an boolean
bool clan::DomElement::get_child_bool_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name, | ||
bool | default_value = false ) const |
Returns the boolean value of the child node with the given local name and namespace.
Finds the first child node with the specified local name and namespace, then returns the content of its first child text node as an boolean
int clan::DomElement::get_child_int | ( | const DomString & | name, |
int | default_value = 0 ) const |
Returns the integer value of the child node with the given tag name.
Finds the first child node with the specified tag name, then returns the content of its first child text node as an integer
int clan::DomElement::get_child_int_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name, | ||
int | default_value = 0 ) const |
Returns the integer value of the child node with the given local name and namespace.
Finds the first child node with the specified local name and namespace, then returns the content of its first child text node as an integer
DomString clan::DomElement::get_child_string | ( | const DomString & | name, |
const DomString & | default_value = DomString() ) const |
Returns the text value of the child node with the given tag name.
Finds the first child node with the specified tag name, then returns the content of its first child text node
DomString clan::DomElement::get_child_string_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name, | ||
const DomString & | default_value = DomString() ) const |
Returns the text value of the child node with the given local name and namespace.
Finds the first child node with the specified local name and namespace, then returns the content of its first child text node
DomNodeList clan::DomElement::get_elements_by_tag_name | ( | const DomString & | name | ) |
Returns a NodeList of all descendant elements with a given tag name.
The descendant elements are returned in the order in which they would be encountered in a preorder traversal of the Element tree.
DomNodeList clan::DomElement::get_elements_by_tag_name_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name ) |
DomElement clan::DomElement::get_first_child_element | ( | ) | const |
Returns the first child node that is an element node.
References DomElement().
DomElement clan::DomElement::get_next_sibling_element | ( | ) | const |
Returns the next sibling node that is an element node.
References DomElement().
DomString clan::DomElement::get_tag_name | ( | ) | const |
Returns the name of the element.
std::string clan::DomElement::get_text | ( | ) | const |
Returns the text of all child Text nodes appended together.
bool clan::DomElement::has_attribute | ( | const DomString & | name | ) | const |
Returns true if the element has the specified attribute.
bool clan::DomElement::has_attribute_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name ) const |
Returns true if the element has the specified attribute.
void clan::DomElement::remove_attribute | ( | const DomString & | name | ) |
Removes an attribute by name.
If the removed attribute has a default value it is immediately replaced.
void clan::DomElement::remove_attribute_ns | ( | const DomString & | namespace_uri, |
const DomString & | local_name ) |
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 is 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 Attr node plus any Text and EntityReference nodes, build the appropriate subtree, and use set_attribute_node to assign it as the value of an attribute.
void clan::DomElement::set_attribute_bool | ( | const DomString & | name, |
bool | value ) |
Sets the attribute node with the specified tag name to the given boolean value.
void clan::DomElement::set_attribute_bool_ns | ( | const DomString & | namespace_uri, |
const DomString & | qualified_name, | ||
bool | value ) |
Sets the attribute node with the specified qualified name and namespace to the given boolean value.
void clan::DomElement::set_attribute_float | ( | const DomString & | name, |
float | value, | ||
int | num_decimal_places = 6 ) |
Sets the attribute node with the specified tag name to the given floating-point value.
void clan::DomElement::set_attribute_float_ns | ( | const DomString & | namespace_uri, |
const DomString & | qualified_name, | ||
float | value, | ||
int | num_decimal_places = 6 ) |
Sets the attribute node with the specified qualified name and namespace to the given floating-point value.
void clan::DomElement::set_attribute_int | ( | const DomString & | name, |
int | value ) |
Sets the attribute node with the specified tag name to the given integer value.
void clan::DomElement::set_attribute_int_ns | ( | const DomString & | namespace_uri, |
const DomString & | qualified_name, | ||
int | value ) |
Sets the attribute node with the specified qualified name and namespace to the given integer value.
Set attribute node.
attr | = Dom Attr |
Set attribute node ns.
attr | = Dom Attr |
void clan::DomElement::set_attribute_ns | ( | const DomString & | namespace_uri, |
const DomString & | qualified_name, | ||
const DomString & | value ) |
void clan::DomElement::set_child_bool | ( | const DomString & | name, |
bool | value ) |
Sets the child node with the specified tag name to the given boolean value.
Sets the first child node with the specified tag name, creating it if it does not exist, to the given boolean value
void clan::DomElement::set_child_bool_ns | ( | const DomString & | namespace_uri, |
const DomString & | qualified_name, | ||
bool | value ) |
Sets the child node with the specified qualified name and namespace to the given boolean value.
Sets the first child node with the specified qualified name and namespace, creating it if it does not exist, to the given boolean value
void clan::DomElement::set_child_int | ( | const DomString & | name, |
int | value ) |
Sets the child node with the specified tag name to the given integer value.
Sets the first child node with the specified tag name, creating it if it does not exist, to the given integer value
void clan::DomElement::set_child_int_ns | ( | const DomString & | namespace_uri, |
const DomString & | qualified_name, | ||
int | value ) |
Sets the child node with the specified qualified name and namespace to the given integer value.
Sets the first child node with the specified qualified name and namespace, creating it if it does not exist, to the given integer value
Sets the child node with the specified tag name to the given text value.
Sets the first child node with the specified tag name, creating it if it does not exist, to the given text value
void clan::DomElement::set_child_string_ns | ( | const DomString & | namespace_uri, |
const DomString & | qualified_name, | ||
const DomString & | value ) |
Sets the child node with the specified qualified name and namespace to the given text value.
Sets the first child node with the specified qualified name and namespace, creating it if it does not exist, to the given text value