libxml++  4.9.1
About: libxml++ is a C++ wrapper for the libxml XML parser library.
  Fossies Dox: libxml++-4.9.1.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

xmlpp::Node Class Reference

Represents XML Nodes. More...

#include <node.h>

Inheritance diagram for xmlpp::Node:
[legend]
Collaboration diagram for xmlpp::Node:
[legend]

Public Types

using NodeList = std::list< Node * >
 
using const_NodeList = std::list< const Node * >
 
using NodeSet = std::vector< Node * >
 
using const_NodeSet = std::vector< const Node * >
 
using PrefixNsMap = std::map< ustring, ustring >
 A map of namespace prefixes to namespace URIs. More...
 

Public Member Functions

 Node (_xmlNode *node)
 
 ~Node () override
 Destructor. More...
 
ustring get_name () const
 Get the name of this node. More...
 
void set_name (const ustring &name)
 Set the name of this node. More...
 
void set_namespace (const ustring &ns_prefix)
 Set the namespace prefix used by the node. More...
 
ustring get_namespace_prefix () const
 Get the namespace prefix of this node. More...
 
ustring get_namespace_uri () const
 Get the namespace URI of this node. More...
 
int get_line () const
 Discover at what line number this node occurs in the XML file. More...
 
const Elementget_parent () const
 Get the parent element for this node. More...
 
Elementget_parent ()
 Get the parent element for this node. More...
 
const Nodeget_next_sibling () const
 Get the next sibling for this node. More...
 
Nodeget_next_sibling ()
 Get the next sibling for this node. More...
 
const Nodeget_previous_sibling () const
 Get the previous sibling for this node . More...
 
Nodeget_previous_sibling ()
 Get the previous sibling for this node. More...
 
const Nodeget_first_child (const ustring &name=ustring()) const
 Get the first child of this node. More...
 
Nodeget_first_child (const ustring &name=ustring())
 Get the first child of this node. More...
 
NodeList get_children (const ustring &name=ustring())
 Obtain the list of child nodes. More...
 
const_NodeList get_children (const ustring &name=ustring()) const
 Obtain the list of child nodes. More...
 
Nodeimport_node (const Node *node, bool recursive=true)
 Import node(s) from another document under this node, without affecting the source node. More...
 
ustring get_path () const
 Get the XPath of this node. More...
 
NodeSet find (const ustring &xpath)
 Find nodes from an XPath expression. More...
 
const_NodeSet find (const ustring &xpath) const
 Find nodes from an XPath expression. More...
 
NodeSet find (const ustring &xpath, const PrefixNsMap &namespaces)
 Find nodes from an XPath expression. More...
 
const_NodeSet find (const ustring &xpath, const PrefixNsMap &namespaces) const
 Find nodes from an XPath expression. More...
 
bool eval_to_boolean (const ustring &xpath, XPathResultType *result_type=nullptr) const
 Evaluate an XPath expression. More...
 
bool eval_to_boolean (const ustring &xpath, const PrefixNsMap &namespaces, XPathResultType *result_type=nullptr) const
 Evaluate an XPath expression. More...
 
double eval_to_number (const ustring &xpath, XPathResultType *result_type=nullptr) const
 Evaluate an XPath expression. More...
 
double eval_to_number (const ustring &xpath, const PrefixNsMap &namespaces, XPathResultType *result_type=nullptr) const
 Evaluate an XPath expression. More...
 
ustring eval_to_string (const ustring &xpath, XPathResultType *result_type=nullptr) const
 Evaluate an XPath expression. More...
 
ustring eval_to_string (const ustring &xpath, const PrefixNsMap &namespaces, XPathResultType *result_type=nullptr) const
 Evaluate an XPath expression. More...
 
_xmlNode * cobj () noexcept
 Access the underlying libxml implementation. More...
 
const _xmlNode * cobj () const noexcept
 Access the underlying libxml implementation. More...
 

Static Public Member Functions

static void remove_node (Node *node)
 Remove a node and its children. More...
 
static void create_wrapper (_xmlNode *node)
 Construct the correct C++ instance for a given libxml C struct instance. More...
 
static void free_wrappers (_xmlNode *node)
 Delete the C++ instance for a given libxml C struct instance, and also recursively destroy the C++ instances for any children. More...
 

Private Attributes

_xmlNode * impl_
 

Additional Inherited Members

- Protected Member Functions inherited from xmlpp::NonCopyable
 NonCopyable () noexcept
 
virtual ~NonCopyable ()
 
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable (NonCopyable &&)=delete
 
NonCopyableoperator= (NonCopyable &&)=delete
 

Detailed Description

Represents XML Nodes.

You should never new and delete Nodes. The Parser will create and manage them for you. Furthermore, Document and Element have methods for adding Nodes to a Document.

Definition at line 51 of file node.h.

Member Typedef Documentation

◆ const_NodeList

using xmlpp::Node::const_NodeList = std::list<const Node*>

Definition at line 55 of file node.h.

◆ const_NodeSet

using xmlpp::Node::const_NodeSet = std::vector<const Node*>

Definition at line 58 of file node.h.

◆ NodeList

using xmlpp::Node::NodeList = std::list<Node*>

Definition at line 54 of file node.h.

◆ NodeSet

using xmlpp::Node::NodeSet = std::vector<Node*>

Definition at line 57 of file node.h.

◆ PrefixNsMap

A map of namespace prefixes to namespace URIs.

Definition at line 213 of file node.h.

Constructor & Destructor Documentation

◆ Node()

xmlpp::Node::Node ( _xmlNode *  node)
explicit
Exceptions
xmlpp::internal_errorIf node is nullptr.

Definition at line 221 of file node.cc.

References impl_.

◆ ~Node()

xmlpp::Node::~Node ( )
override

Destructor.

Does not destroy the underlying xmlNode. The xmlNode is owned by a xmlDoc document. If you want to also destroy the xmlNode, use remove_node().

Definition at line 230 of file node.cc.

Member Function Documentation

◆ cobj() [1/2]

const xmlNode * xmlpp::Node::cobj ( ) const
noexcept

Access the underlying libxml implementation.

Definition at line 384 of file node.cc.

References impl_.

◆ cobj() [2/2]

◆ create_wrapper()

◆ eval_to_boolean() [1/2]

bool xmlpp::Node::eval_to_boolean ( const ustring xpath,
const PrefixNsMap namespaces,
XPathResultType result_type = nullptr 
) const

Evaluate an XPath expression.

Parameters
xpathThe XPath expression.
namespacesA map of namespace prefixes to namespace URIs to be used while evaluating.
[out]result_typeResult type of the XPath expression before conversion to boolean. If nullptr, the result type is not returned.
Returns
The value of the XPath expression. If the value is not of type boolean, it is converted to boolean.
Exceptions
xmlpp::exceptionIf the XPath expression cannot be evaluated.
xmlpp::internal_error
Since @PACKAGE_NAME@ 2.36:

Definition at line 422 of file node.cc.

References impl_.

◆ eval_to_boolean() [2/2]

bool xmlpp::Node::eval_to_boolean ( const ustring xpath,
XPathResultType result_type = nullptr 
) const

Evaluate an XPath expression.

Parameters
xpathThe XPath expression.
[out]result_typeResult type of the XPath expression before conversion to boolean. If nullptr, the result type is not returned.
Returns
The value of the XPath expression. If the value is not of type boolean, it is converted to boolean.
Exceptions
xmlpp::exceptionIf the XPath expression cannot be evaluated.
xmlpp::internal_error
Since @PACKAGE_NAME@ 2.36:

Definition at line 417 of file node.cc.

References impl_.

◆ eval_to_number() [1/2]

double xmlpp::Node::eval_to_number ( const ustring xpath,
const PrefixNsMap namespaces,
XPathResultType result_type = nullptr 
) const

Evaluate an XPath expression.

Parameters
xpathThe XPath expression.
namespacesA map of namespace prefixes to namespace URIs to be used while evaluating.
[out]result_typeResult type of the XPath expression before conversion to number. If nullptr, the result type is not returned.
Returns
The value of the XPath expression. If the value is not of type number, it is converted to number.
Exceptions
xmlpp::exceptionIf the XPath expression cannot be evaluated.
xmlpp::internal_error
Since @PACKAGE_NAME@ 2.36:

Definition at line 433 of file node.cc.

References impl_.

◆ eval_to_number() [2/2]

double xmlpp::Node::eval_to_number ( const ustring xpath,
XPathResultType result_type = nullptr 
) const

Evaluate an XPath expression.

Parameters
xpathThe XPath expression.
[out]result_typeResult type of the XPath expression before conversion to number. If nullptr, the result type is not returned.
Returns
The value of the XPath expression. If the value is not of type number, it is converted to number.
Exceptions
xmlpp::exceptionIf the XPath expression cannot be evaluated.
xmlpp::internal_error
Since @PACKAGE_NAME@ 2.36:

Definition at line 428 of file node.cc.

References impl_.

◆ eval_to_string() [1/2]

ustring xmlpp::Node::eval_to_string ( const ustring xpath,
const PrefixNsMap namespaces,
XPathResultType result_type = nullptr 
) const

Evaluate an XPath expression.

Parameters
xpathThe XPath expression.
namespacesA map of namespace prefixes to namespace URIs to be used while evaluating.
[out]result_typeResult type of the XPath expression before conversion to string. If nullptr, the result type is not returned.
Returns
The value of the XPath expression. If the value is not of type string, it is converted to string.
Exceptions
xmlpp::exceptionIf the XPath expression cannot be evaluated.
xmlpp::internal_error
Since @PACKAGE_NAME@ 2.36:

Definition at line 444 of file node.cc.

References impl_.

◆ eval_to_string() [2/2]

ustring xmlpp::Node::eval_to_string ( const ustring xpath,
XPathResultType result_type = nullptr 
) const

Evaluate an XPath expression.

Parameters
xpathThe XPath expression.
[out]result_typeResult type of the XPath expression before conversion to string. If nullptr, the result type is not returned.
Returns
The value of the XPath expression. If the value is not of type string, it is converted to string.
Exceptions
xmlpp::exceptionIf the XPath expression cannot be evaluated.
xmlpp::internal_error
Since @PACKAGE_NAME@ 2.36:

Definition at line 439 of file node.cc.

References impl_.

◆ find() [1/4]

Node::NodeSet xmlpp::Node::find ( const ustring xpath)

Find nodes from an XPath expression.

Parameters
xpathThe XPath of the nodes.
Returns
The resulting NodeSet.
Exceptions
xmlpp::exceptionIf the XPath expression cannot be evaluated.
xmlpp::internal_errorIf the result type is not nodeset.

Definition at line 397 of file node.cc.

References impl_.

◆ find() [2/4]

Node::const_NodeSet xmlpp::Node::find ( const ustring xpath) const

Find nodes from an XPath expression.

Parameters
xpathThe XPath of the nodes.
Returns
The resulting const_NodeSet.
Exceptions
xmlpp::exceptionIf the XPath expression cannot be evaluated.
xmlpp::internal_errorIf the result type is not nodeset.

Definition at line 402 of file node.cc.

References impl_.

◆ find() [3/4]

Node::NodeSet xmlpp::Node::find ( const ustring xpath,
const PrefixNsMap namespaces 
)

Find nodes from an XPath expression.

Parameters
xpathThe XPath of the nodes.
namespacesA map of namespace prefixes to namespace URIs to be used while finding.
Returns
The resulting NodeSet.
Exceptions
xmlpp::exceptionIf the XPath expression cannot be evaluated.
xmlpp::internal_errorIf the result type is not nodeset.

Definition at line 407 of file node.cc.

References impl_.

◆ find() [4/4]

Node::const_NodeSet xmlpp::Node::find ( const ustring xpath,
const PrefixNsMap namespaces 
) const

Find nodes from an XPath expression.

Parameters
xpathThe XPath of the nodes.
namespacesA map of namespace prefixes to namespace URIs to be used while finding.
Returns
The resulting const_NodeSet.
Exceptions
xmlpp::exceptionIf the XPath expression cannot be evaluated.
xmlpp::internal_errorIf the result type is not nodeset.

Definition at line 412 of file node.cc.

References impl_.

◆ free_wrappers()

void xmlpp::Node::free_wrappers ( _xmlNode *  node)
static

Delete the C++ instance for a given libxml C struct instance, and also recursively destroy the C++ instances for any children.

This is only for use by the libxml++ implementation.

Parameters
nodeA pointer to an xmlNode or a "derived" struct, such as xmlDoc, xmlAttr, etc.

Definition at line 609 of file node.cc.

Referenced by xmlpp::Document::create_root_node(), xmlpp::Document::create_root_node_by_import(), import_node(), xmlpp::Element::remove_attribute(), remove_node(), and xmlpp::Document::~Document().

◆ get_children() [1/2]

Node::NodeList xmlpp::Node::get_children ( const ustring name = ustring())

Obtain the list of child nodes.

You may optionally obtain a list of only the child nodes which have a certain name.

Parameters
nameThe names of the child nodes to get. If you do not specify a name, then the list will contain all nodes, regardless of their names.
Returns
The list of child nodes.

Definition at line 296 of file node.cc.

References impl_.

◆ get_children() [2/2]

Node::const_NodeList xmlpp::Node::get_children ( const ustring name = ustring()) const

Obtain the list of child nodes.

You may optionally obtain a list of only the child nodes which have a certain name.

Parameters
nameThe names of the child nodes to get. If you do not specify a name, then the list will contain all nodes, regardless of their names.
Returns
The list of child nodes.

Definition at line 301 of file node.cc.

References impl_.

◆ get_first_child() [1/2]

Node * xmlpp::Node::get_first_child ( const ustring name = ustring())

Get the first child of this node.

You may optionally get the first child node which has a certain name.

Parameters
nameThe name of the requested child node, or an empty string.
Returns
The first child, or nullptr if no child node (with the specified name) exists.
Since @PACKAGE_NAME@ 2.36:

Definition at line 275 of file node.cc.

References impl_.

◆ get_first_child() [2/2]

const Node * xmlpp::Node::get_first_child ( const ustring name = ustring()) const

Get the first child of this node.

You may optionally get the first child node which has a certain name.

Parameters
nameThe name of the requested child node, or an empty string.
Returns
The first child, or nullptr if no child node (with the specified name) exists.
Since @PACKAGE_NAME@ 2.36:

Definition at line 291 of file node.cc.

◆ get_line()

int xmlpp::Node::get_line ( ) const

Discover at what line number this node occurs in the XML file.

Returns
The line number.

Definition at line 373 of file node.cc.

References impl_.

◆ get_name()

ustring xmlpp::Node::get_name ( ) const

Get the name of this node.

Returns
The node's name.

Definition at line 363 of file node.cc.

References impl_.

◆ get_namespace_prefix()

ustring xmlpp::Node::get_namespace_prefix ( ) const

Get the namespace prefix of this node.

Returns
The node's namespace prefix. Can be an empty string.

Definition at line 450 of file node.cc.

References impl_.

Referenced by xmlpp::Element::set_namespace_declaration().

◆ get_namespace_uri()

ustring xmlpp::Node::get_namespace_uri ( ) const

Get the namespace URI of this node.

Returns
The node's namespace URI. Can be an empty string.

Definition at line 475 of file node.cc.

References impl_.

◆ get_next_sibling() [1/2]

Node * xmlpp::Node::get_next_sibling ( )

Get the next sibling for this node.

Returns
The next sibling, or nullptr if the node has no next sibling.

Definition at line 252 of file node.cc.

References cobj(), and create_wrapper().

◆ get_next_sibling() [2/2]

const Node * xmlpp::Node::get_next_sibling ( ) const

Get the next sibling for this node.

Returns
The next sibling, or nullptr if the node has no next sibling.

Definition at line 247 of file node.cc.

◆ get_parent() [1/2]

Element * xmlpp::Node::get_parent ( )

Get the parent element for this node.

Returns
The parent node, or nullptr if the node has no parent element.

Definition at line 238 of file node.cc.

References cobj(), and create_wrapper().

◆ get_parent() [2/2]

const Element * xmlpp::Node::get_parent ( ) const

Get the parent element for this node.

Returns
The parent node, or nullptr if the node has no parent element.

Definition at line 233 of file node.cc.

◆ get_path()

ustring xmlpp::Node::get_path ( ) const

Get the XPath of this node.

Returns
The XPath of the node.

Definition at line 389 of file node.cc.

References impl_.

◆ get_previous_sibling() [1/2]

Node * xmlpp::Node::get_previous_sibling ( )

Get the previous sibling for this node.

Returns
The previous sibling, or nullptr if the node has no previous sibling.

Definition at line 266 of file node.cc.

References cobj(), and create_wrapper().

◆ get_previous_sibling() [2/2]

const Node * xmlpp::Node::get_previous_sibling ( ) const

Get the previous sibling for this node .

Returns
The previous sibling, or nullptr if the node has no previous sibling.

Definition at line 261 of file node.cc.

◆ import_node()

Node * xmlpp::Node::import_node ( const Node node,
bool  recursive = true 
)

Import node(s) from another document under this node, without affecting the source node.

If the imported node is an attribute node, and this node has an attribute with the same name as the imported attribute, the existing attribute is destroyed before the imported attribute is added. Any pointer to a destroyed attribute node becomes invalid.

Parameters
nodeThe node to copy and insert under the current node.
recursiveWhether to import the child nodes also. Defaults to true.
Returns
Usually the newly created node, but adjacent text nodes are merged, and the old text node with merged contents is returned.
Exceptions
xmlpp::exception

Definition at line 320 of file node.cc.

References cobj(), create_wrapper(), free_wrappers(), and impl_.

◆ remove_node()

void xmlpp::Node::remove_node ( Node node)
static

Remove a node and its children.

The node is disconnected from its parent. The underlying libxml xmlNode instances are also removed.

Since @PACKAGE_NAME@ 3.0:
Replaces remove_child()
Parameters
nodeThe node to remove. This Node and all its descendants will be deleted and therefore unusable after calling this method.

Definition at line 307 of file node.cc.

References cobj(), and free_wrappers().

◆ set_name()

void xmlpp::Node::set_name ( const ustring name)

Set the name of this node.

Parameters
nameThe new name for the node.

Definition at line 368 of file node.cc.

References impl_.

◆ set_namespace()

void xmlpp::Node::set_namespace ( const ustring ns_prefix)

Set the namespace prefix used by the node.

If no such namespace prefix has been declared then this method will throw an exception.

Parameters
ns_prefixThe namespace prefix.
Exceptions
xmlpp::exception

Definition at line 497 of file node.cc.

References cobj(), and impl_.

Referenced by xmlpp::Element::set_namespace_declaration().

Member Data Documentation

◆ impl_


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