Representation for an element in the DOM.
More...
#include <dom.h>
|
|
| DOMElement () |
| | CTOR.
|
| |
|
| ~DOMElement () |
| | DTOR.
|
| |
| | DOMElement (const DOMElement &element) |
| |
| DOMElement & | operator= (const DOMElement &element) |
| |
| std::string | getAttribute (const std::string &name, const std::string &def_value=std::string()) const |
| |
| DOMAttributes | getAttributes () const |
| |
| DOMElement | getChild (const std::string &name) const |
| |
| DOMElementList | getChildren () const |
| |
| std::string | getData () const |
| |
| DOM | getDocument () const |
| |
| std::string | getName () const |
| |
| DOMElement | getParent () const |
| |
| std::string | getPath () const |
| |
| bool | setAttribute (const std::string &name, const std::string &strValue) |
| |
| bool | setData (const std::string &data) |
| |
| bool | setName (const std::string &name) |
| |
| bool | hasAttribute (const std::string &name) const |
| |
| bool | eraseAttribute (const std::string &name) |
| |
| bool | findNode (const std::string &query, DOMElement &element_ptr) const |
| |
| bool | findNodes (const std::string &query, DOMElementList &elements) const |
| |
| bool | sortNodes (const std::string &query, SortingOrder order) |
| |
| bool | sortNodes (const std::string &query, SortingOrder order, std::size_t number_of_nodes) |
| |
| std::size_t | sortNodes (const std::string &query, const std::string &attribute, SortingOrder order) |
| |
| bool | sortNodes (const std::string &query, const std::string &attribute, SortingOrder order, std::size_t number_of_nodes) |
| |
| DOMElement | createChild (const std::string &name) |
| |
| DOMElement | createChildBefore (const std::string &name, const DOMElement &before) |
| |
| bool | removeChild (const std::string &name) |
| |
| bool | isNull () const |
| |
Representation for an element in the DOM.
◆ DOMElement()
| a_util::xml::DOMElement::DOMElement |
( |
const DOMElement & | element | ) |
|
Copy constructor.
- Parameters
-
| [in] | element | The object to copy from |
◆ createChild()
| DOMElement a_util::xml::DOMElement::createChild |
( |
const std::string & | name | ) |
|
Creates a new child element
- Parameters
-
| [in] | name | The name of the child |
- Returns
- The new child
◆ createChildBefore()
| DOMElement a_util::xml::DOMElement::createChildBefore |
( |
const std::string & | name, |
|
|
const DOMElement & | before ) |
Creates a new child element before an existing child element
- Parameters
-
| [in] | name | The name of the child |
| [in] | before | The existing child element |
- Returns
- The new child
◆ eraseAttribute()
| bool a_util::xml::DOMElement::eraseAttribute |
( |
const std::string & | name | ) |
|
Removes an attribute
- Parameters
-
| [in] | name | The name of the attribute |
- Returns
true if the attribute was erased, false otherwise
◆ findNode()
| bool a_util::xml::DOMElement::findNode |
( |
const std::string & | query, |
|
|
DOMElement & | element_ptr ) const |
Finds a node based on a query.
Some basic syntax:
- queries starting with '/' are starting at the root node
- use '*' to search all child nodes in the path
- if you search with absolute paths, don't forget to use the root node in the path.
- to search for certain attributes on nodes use [@property0='value'] or [@property0] to check the existence. Keep in mind that attributes search method will include parent (root) node in the elements list if search value match. In this case parent node will be the first element in the list.
- attributes can be concatenated to make them behave like an AND: [@property0][@property1='value']
- recursive search from root starts with '//nodes_to_search'. The whole tree is being searched.
- recursive search from current node starts with './/nodes_to_search'. The whole subtree is being searched.
- use 'and' or 'or' to connect multiple properties logically (USE ONLY ONE OPERATOR!)
Here are some examples of search queries.
- /root/path/to/node :absolute path to nodes
- path/to/node :search starting on current node. Same as above, if searched in root node.
- /root/node/* :find all children of all 'node' nodes
- * :find all children of current node
- /root/node[@prop='2']/* :find all children of 'node' nodes with matching attribute
- //node :finds all 'node' nodes in the tree (recursive search)
- .//node :recursive search starting from current node
- //*[@prop='2'] :find all nodes in the tree with matching attributes
- /root/path/to[@prop='2']//node :find all 'node' nodes in the subtree of the sub paths '/root/path/to'
- child/*[@prop1='2'] :find all nodes in 'child' nodes with matching attributes
- *[@prop1='3' and @prop2='4'] :logical AND comparison for attributes
- Parameters
-
| [in] | query | The query string |
| [out] | element_ptr | This will point to the found element |
- Returns
false if no matching node is found or the query is invalid, true otherwise
◆ findNodes()
| bool a_util::xml::DOMElement::findNodes |
( |
const std::string & | query, |
|
|
DOMElementList & | elements ) const |
Finds nodes based on a query.
See findNode() for the syntax.
- Parameters
-
| [in] | query | The query string |
| [out] | elements | This list will be filled with the found elements |
- Returns
false if no matching node is found or the query is invalid, true otherwise
◆ getAttribute()
| std::string a_util::xml::DOMElement::getAttribute |
( |
const std::string & | name, |
|
|
const std::string & | def_value = std::string() ) const |
Returns the value of an attribute with name
- Parameters
-
| [in] | name | The name of the attribute |
| [in] | def_value | A default value that is returned if the attribute does not exist |
- Returns
- The value of the attribute or the default value
◆ getAttributes()
Get a map of all attributes of this element
- Returns
- A map of all attributes of the element
◆ getChild()
| DOMElement a_util::xml::DOMElement::getChild |
( |
const std::string & | name | ) |
const |
Get the first child mathing the name of this element
- Parameters
-
| [in] | name | The name of the child element |
- Returns
- The child element or a
nullptr if not found
◆ getChildren()
Get a list of all child elements of the element
- Returns
- The element list of all children
◆ getData()
| std::string a_util::xml::DOMElement::getData |
( |
| ) |
const |
Get the data of the element.
- Returns
- The data
◆ getDocument()
| DOM a_util::xml::DOMElement::getDocument |
( |
| ) |
const |
Get the DOM document this element belongs to
- Returns
- The document this element belongs to
◆ getName()
| std::string a_util::xml::DOMElement::getName |
( |
| ) |
const |
Get the name of the element
- Returns
- The name of the element
◆ getParent()
| DOMElement a_util::xml::DOMElement::getParent |
( |
| ) |
const |
Get this elements parent element
- Returns
- The parent element - empty if no parent element exists
◆ getPath()
| std::string a_util::xml::DOMElement::getPath |
( |
| ) |
const |
Get current path of the element
- Returns
- Returns the path
◆ hasAttribute()
| bool a_util::xml::DOMElement::hasAttribute |
( |
const std::string & | name | ) |
const |
Checks if an attribute exists
- Parameters
-
| [in] | name | The name of the attribute |
- Returns
true if attribute exists, otherwise false
◆ isNull()
| bool a_util::xml::DOMElement::isNull |
( |
| ) |
const |
Check whether this DOMElement is empty
- Returns
true if empty, false otherwise
◆ operator=()
Copy assignment operator.
- Parameters
-
| [in] | element | The element to copy from |
- Returns
- *this
◆ removeChild()
| bool a_util::xml::DOMElement::removeChild |
( |
const std::string & | name | ) |
|
Erases the first child of that name in this element
- Parameters
-
| name | [in] The name of the child element |
- Returns
true if the child was removed, false otherwise
◆ setAttribute()
| bool a_util::xml::DOMElement::setAttribute |
( |
const std::string & | name, |
|
|
const std::string & | strValue ) |
Sets an attribute. Setting an attribute on an DOMElement object not created from an existing DOM will fail as a DOMElement needs to be linked to a valid DOM
- Parameters
-
| [in] | name | The attribute name |
| [in] | strValue | The value of the attribute |
- Returns
false if its an invalid attribute name, true otherwise
◆ setData()
| bool a_util::xml::DOMElement::setData |
( |
const std::string & | data | ) |
|
Sets the data of the element. Setting the data on an DOMElement object not created from an existing DOM will fail as a DOMElement needs to be linked to a valid DOM
- Parameters
-
- Returns
true if the data was set, false otherwise
◆ setName()
| bool a_util::xml::DOMElement::setName |
( |
const std::string & | name | ) |
|
Sets the name of the element. Setting the name on an DOMElement object not created from an existing DOM will fail as a DOMElement needs to be linked to a valid DOM
- Parameters
-
- Returns
true if the name was set, false otherwise.
◆ sortNodes() [1/4]
| std::size_t a_util::xml::DOMElement::sortNodes |
( |
const std::string & | query, |
|
|
const std::string & | attribute, |
|
|
SortingOrder | order ) |
Sort the queried nodes by attribute example:
bool sortNodes(const std::string &query, SortingOrder order)
@ ascending
Sort in ascending order.
Definition enums.h:24
- Parameters
-
| [in] | query | Xpath that describes the nodes to sort |
| [in] | attribute | Attribute name of nodes to sort in specified order |
| [in] | order | Sort nodes in ascending or descending order |
- Returns
- Number of nodes found by the query
◆ sortNodes() [2/4]
| bool a_util::xml::DOMElement::sortNodes |
( |
const std::string & | query, |
|
|
const std::string & | attribute, |
|
|
SortingOrder | order, |
|
|
std::size_t | number_of_nodes ) |
Sort all queried nodes by attribute example:
'[*]' in query will be replaced successively by numbers in range [1]..[n]
- Parameters
-
| [in] | query | Xpath that describes all nodes to sort |
| [in] | attribute | Attribute name of nodes to sort in specified order |
| [in] | order | Sort nodes of queries in ascending/descending order |
| [in] | number_of_nodes | Number of nodes to be sorted successively |
- Returns
- false if no matching nodes are found or any query is invalid, true otherwise
◆ sortNodes() [3/4]
| bool a_util::xml::DOMElement::sortNodes |
( |
const std::string & | query, |
|
|
SortingOrder | order ) |
Sort the queried nodes by name example:
- Parameters
-
| [in] | query | Xpath that describes the nodes to sort |
| [in] | order | Sort nodes in ascending or descending order |
- Returns
- false if no matching node is found or the query is invalid, true otherwise
◆ sortNodes() [4/4]
| bool a_util::xml::DOMElement::sortNodes |
( |
const std::string & | query, |
|
|
SortingOrder | order, |
|
|
std::size_t | number_of_nodes ) |
Sort all queried nodes by name example:
'[*]' in query will be replaced successively by numbers in range [1]..[n]
- Parameters
-
| [in] | query | Xpath that describes all nodes to sort |
| [in] | order | Sort nodes of queries in ascending/descending order |
| [in] | number_of_nodes | Number of nodes to be sorted successively |
- Returns
- false if no matching nodes are found or any query is invalid, true otherwise
◆ operator==
Comparison operator.
- Parameters
-
| lhs | [in] Left instance |
| rhs | [in] Right instance |
- Returns
true if the two instances are equal (deep comparison)
The documentation for this class was generated from the following file: