libxml++
2.40.1
|
Element nodes have attributes as well as child nodes. More...
#include <libxml++/nodes/element.h>
Public Types | |
typedef std::list< Attribute* > | AttributeList |
![]() | |
typedef std::list< Node* > | NodeList |
typedef std::map< Glib::ustring, Glib::ustring > | PrefixNsMap |
A map of namespace prefixes to namespace URIs. More... | |
Public Member Functions | |
Element (_xmlNode* node) | |
~Element () override | |
CdataNode* | add_child_cdata (const Glib::ustring& content) |
Append a new CDATA node. More... | |
CommentNode* | add_child_comment (const Glib::ustring& content) |
Append a new comment node. More... | |
EntityReference* | add_child_entity_reference (const Glib::ustring& name) |
Append a new entity reference node. More... | |
ProcessingInstructionNode* | add_child_processing_instruction (const Glib::ustring& name, const Glib::ustring& content) |
Append a new processing instruction node. More... | |
TextNode* | add_child_text (const Glib::ustring& content=Glib::ustring()) |
Append a new text node. More... | |
TextNode* | add_child_text (xmlpp::Node* previous_sibling, const Glib::ustring& content=Glib::ustring()) |
Add a new text node after the specified existing child node. More... | |
TextNode* | add_child_text_before (xmlpp::Node* next_sibling, const Glib::ustring& content=Glib::ustring()) |
Add a new text node before the specified existing child node. More... | |
Attribute* | get_attribute (const Glib::ustring& name, const Glib::ustring& ns_prefix=Glib::ustring()) const |
Get the attribute with this name, and optionally with this namespace. More... | |
Glib::ustring | get_attribute_value (const Glib::ustring& name, const Glib::ustring& ns_prefix=Glib::ustring()) const |
Get the value of the attribute with this name, and optionally with this namespace. More... | |
AttributeList | get_attributes () |
Obtain the list of explicitly set attributes for this element. More... | |
const AttributeList | get_attributes () const |
Obtain the list of explicitly set attributes for this element. More... | |
TextNode* | get_child_text () |
Get the first child text content node. More... | |
const TextNode* | get_child_text () const |
Get the first child text content node. More... | |
bool | has_child_text () const |
Discover whether one of the child nodes is a text node. More... | |
void | remove_attribute (const Glib::ustring& name, const Glib::ustring& ns_prefix=Glib::ustring()) |
Remove the attribute with this name, and optionally with this namespace. More... | |
Attribute* | set_attribute (const Glib::ustring& name, const Glib::ustring& value, const Glib::ustring& ns_prefix=Glib::ustring()) |
Set the value of the attribute with this name, and optionally with this namespace. More... | |
void | set_child_text (const Glib::ustring& content) |
Set the text of the first text node, adding one if necessary. More... | |
void | set_namespace_declaration (const Glib::ustring& ns_uri, const Glib::ustring& ns_prefix=Glib::ustring()) |
Add a namespace declaration to this node which will apply to this node and all children. More... | |
![]() | |
Node (_xmlNode* node) | |
~Node () override | |
Element* | add_child (const Glib::ustring& name, const Glib::ustring& ns_prefix=Glib::ustring()) |
Add a child element to this node. More... | |
Element* | add_child (xmlpp::Node* previous_sibling, const Glib::ustring& name, const Glib::ustring& ns_prefix=Glib::ustring()) |
Add a child element to this node after the specified existing child node. More... | |
Element* | add_child_before (xmlpp::Node* next_sibling, const Glib::ustring& name, const Glib::ustring& ns_prefix=Glib::ustring()) |
Add a child element to this node before the specified existing child node. More... | |
Element* | add_child_before_with_new_ns (xmlpp::Node* next_sibling, const Glib::ustring& name, const Glib::ustring& ns_uri, const Glib::ustring& ns_prefix=Glib::ustring()) |
Add a child element to this node before the specified existing child node. More... | |
Element* | add_child_with_new_ns (const Glib::ustring& name, const Glib::ustring& ns_uri, const Glib::ustring& ns_prefix=Glib::ustring()) |
Add a child element to this node. More... | |
Element* | add_child_with_new_ns (xmlpp::Node* previous_sibling, const Glib::ustring& name, const Glib::ustring& ns_uri, const Glib::ustring& ns_prefix=Glib::ustring()) |
Add a child element to this node after the specified existing child node. More... | |
_xmlNode* | cobj () |
Access the underlying libxml implementation. More... | |
const _xmlNode* | cobj () const |
Access the underlying libxml implementation. More... | |
bool | eval_to_boolean (const Glib::ustring& xpath, XPathResultType* result_type=nullptr) const |
Evaluate an XPath expression. More... | |
bool | eval_to_boolean (const Glib::ustring& xpath, const PrefixNsMap& namespaces, XPathResultType* result_type=nullptr) const |
Evaluate an XPath expression. More... | |
double | eval_to_number (const Glib::ustring& xpath, XPathResultType* result_type=nullptr) const |
Evaluate an XPath expression. More... | |
double | eval_to_number (const Glib::ustring& xpath, const PrefixNsMap& namespaces, XPathResultType* result_type=nullptr) const |
Evaluate an XPath expression. More... | |
Glib::ustring | eval_to_string (const Glib::ustring& xpath, XPathResultType* result_type=nullptr) const |
Evaluate an XPath expression. More... | |
Glib::ustring | eval_to_string (const Glib::ustring& xpath, const PrefixNsMap& namespaces, XPathResultType* result_type=nullptr) const |
Evaluate an XPath expression. More... | |
NodeSet | find (const Glib::ustring& xpath) const |
Find nodes from an XPath expression. More... | |
NodeSet | find (const Glib::ustring& xpath, const PrefixNsMap& namespaces) const |
Find nodes from an XPath expression. More... | |
NodeList | get_children (const Glib::ustring& name=Glib::ustring()) |
Obtain the list of child nodes. More... | |
const NodeList | get_children (const Glib::ustring& name=Glib::ustring()) const |
Obtain the list of child nodes. More... | |
const Node* | get_first_child (const Glib::ustring& name=Glib::ustring()) const |
Get the first child of this node. More... | |
Node* | get_first_child (const Glib::ustring& name=Glib::ustring()) |
Get the first child of this node. More... | |
int | get_line () const |
Discover at what line number this node occurs in the XML file. More... | |
Glib::ustring | get_name () const |
Get the name of this node. More... | |
Glib::ustring | get_namespace_prefix () const |
Get the namespace prefix of this node. More... | |
Glib::ustring | get_namespace_uri () const |
Get the namespace URI of this node. More... | |
const Node* | get_next_sibling () const |
Get the next sibling for this node. More... | |
Node* | get_next_sibling () |
Get the next sibling for this node. More... | |
const Element* | get_parent () const |
Get the parent element for this node. More... | |
Element* | get_parent () |
Get the parent element for this node. More... | |
Glib::ustring | get_path () const |
Get the XPath of this node. More... | |
const Node* | get_previous_sibling () const |
Get the previous sibling for this node . More... | |
Node* | get_previous_sibling () |
Get the previous sibling for this node. More... | |
Node* | import_node (const Node* node, bool recursive=true) |
Import node(s) from another document under this node, without affecting the source node. More... | |
void | remove_child (Node* node) |
Remove the child node. More... | |
void | set_name (const Glib::ustring& name) |
Set the name of this node. More... | |
void | set_namespace (const Glib::ustring& ns_prefix) |
Set the namespace prefix used by the node. More... | |
Protected Member Functions | |
Glib::ustring | get_namespace_uri_for_prefix (const Glib::ustring& ns_prefix) const |
![]() | |
_xmlNode* | create_new_child_node (const Glib::ustring& name, const Glib::ustring& ns_prefix) |
Create the C instance ready to be added to the parent node. More... | |
_xmlNode* | create_new_child_node_with_new_ns (const Glib::ustring& name, const Glib::ustring& ns_uri, const Glib::ustring& ns_prefix) |
Create the C instance ready to be added to the parent node. More... | |
![]() | |
NonCopyable () | |
NonCopyable (const NonCopyable&)=delete | |
virtual | ~NonCopyable () |
NonCopyable& | operator= (const NonCopyable&)=delete |
Additional Inherited Members | |
![]() | |
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... | |
Element nodes have attributes as well as child nodes.
This will be instantiated by the parser.
typedef std::list<Attribute*> xmlpp::Element::AttributeList |
|
explicit |
|
override |
CdataNode* xmlpp::Element::add_child_cdata | ( | const Glib::ustring & | content | ) |
Append a new CDATA node.
content | The raw text. |
xmlpp::internal_error |
CommentNode* xmlpp::Element::add_child_comment | ( | const Glib::ustring & | content | ) |
Append a new comment node.
content | The text. This should be unescaped - see ContentNode::set_content(). |
xmlpp::internal_error |
EntityReference* xmlpp::Element::add_child_entity_reference | ( | const Glib::ustring & | name | ) |
Append a new entity reference node.
The reference can be either an entity reference ("name" or "&name;") or a character reference ("#dec", "#xhex", "&#dec;", or "&#xhex;").
'&' and ';' are optional. If they exist, they are stripped from the stored copy of the name. Node::get_name() returns the name without '&' and ';'. If the Document is written to an XML file, '&' and ';' are written.
name | The name of the entity. |
xmlpp::internal_error |
ProcessingInstructionNode* xmlpp::Element::add_child_processing_instruction | ( | const Glib::ustring & | name, |
const Glib::ustring & | content | ||
) |
Append a new processing instruction node.
name | The name of the application to which the instruction is directed. |
content | The content of the instruction. This should be unescaped - see ContentNode::set_content(). |
xmlpp::internal_error |
TextNode* xmlpp::Element::add_child_text | ( | const Glib::ustring & | content = Glib::ustring() | ) |
Append a new text node.
content | The text. This should be unescaped - see ContentNode::set_content(). |
xmlpp::internal_error |
TextNode* xmlpp::Element::add_child_text | ( | xmlpp::Node* | previous_sibling, |
const Glib::ustring & | content = Glib::ustring() |
||
) |
Add a new text node after the specified existing child node.
previous_sibling | An existing child node. |
content | The text. This should be unescaped - see ContentNode::set_content(). |
xmlpp::internal_error |
TextNode* xmlpp::Element::add_child_text_before | ( | xmlpp::Node* | next_sibling, |
const Glib::ustring & | content = Glib::ustring() |
||
) |
Add a new text node before the specified existing child node.
next_sibling | An existing child node. |
content | The text. This should be unescaped - see ContentNode::set_content(). |
xmlpp::internal_error |
Attribute* xmlpp::Element::get_attribute | ( | const Glib::ustring & | name, |
const Glib::ustring & | ns_prefix = Glib::ustring() |
||
) | const |
Get the attribute with this name, and optionally with this namespace.
name | The name of the attribute that will be retrieved. |
ns_prefix | Namespace prefix. |
nullptr
if no suitable Attribute was found. Is either an AttributeNode*, pointing to an explicitly set attribute, or an AttributeDeclaration*, pointing to the declaration of an attribute with a default value. Glib::ustring xmlpp::Element::get_attribute_value | ( | const Glib::ustring & | name, |
const Glib::ustring & | ns_prefix = Glib::ustring() |
||
) | const |
Get the value of the attribute with this name, and optionally with this namespace.
For finer control, you might use get_attribute() and use the methods of the Attribute class.
name | The name of the attribute whose value will be retrieved. |
ns_prefix | Namespace prefix. |
AttributeList xmlpp::Element::get_attributes | ( | ) |
Obtain the list of explicitly set attributes for this element.
const AttributeList xmlpp::Element::get_attributes | ( | ) | const |
Obtain the list of explicitly set attributes for this element.
TextNode* xmlpp::Element::get_child_text | ( | ) |
Get the first child text content node.
This is a convenience method, meant as an alternative to iterating over all the child nodes to find the first suitable node then and getting the text directly.
const TextNode* xmlpp::Element::get_child_text | ( | ) | const |
Get the first child text content node.
This is a convenience method, meant as an alternative to iterating over all the child nodes to find the first suitable node then and getting the text directly.
|
protected |
bool xmlpp::Element::has_child_text | ( | ) | const |
Discover whether one of the child nodes is a text node.
This is a convenience method, meant as an alternative to iterating over all the child nodes and examining them directly.
void xmlpp::Element::remove_attribute | ( | const Glib::ustring & | name, |
const Glib::ustring & | ns_prefix = Glib::ustring() |
||
) |
Remove the attribute with this name, and optionally with this namespace.
name | The name of the attribute to be removed |
ns_prefix | Namespace prefix. If specified, the attribute will be removed only if the attribute has this namespace. |
Attribute* xmlpp::Element::set_attribute | ( | const Glib::ustring & | name, |
const Glib::ustring & | value, | ||
const Glib::ustring & | ns_prefix = Glib::ustring() |
||
) |
Set the value of the attribute with this name, and optionally with this namespace.
A matching attribute will be added if no matching attribute already exists. For finer control, you might want to use get_attribute() and use the methods of the Attribute class.
name | The name of the attribute whose value will change. |
value | The new value for the attribute |
ns_prefix | Namespace prefix. If the prefix has not been declared then this method will throw an exception. |
nullptr
is no suitable Attribute was found. xmlpp::exception |
void xmlpp::Element::set_child_text | ( | const Glib::ustring & | content | ) |
Set the text of the first text node, adding one if necessary.
This is a convenience method, meant as an alternative to iterating over all the child nodes to find the first suitable node then and setting the text directly.
content | The text. This should be unescaped - see ContentNode::set_content(). |
xmlpp::internal_error |
void xmlpp::Element::set_namespace_declaration | ( | const Glib::ustring & | ns_uri, |
const Glib::ustring & | ns_prefix = Glib::ustring() |
||
) |
Add a namespace declaration to this node which will apply to this node and all children.
If the added namespace prefix is equal to the prefix associated to the node, the associated namespace of the node itself is updated, but child nodes are not updated. If you use this method on a node after children have been added, it may be necessary to save the XML document and reparse it to get correct namespaces on all nodes.
ns_uri | The namespace to associate with the prefix, or to use as the default namespace if no prefix is specified. |
ns_prefix | The namespace prefix. If no prefix is specified then the namespace URI will be the default namespace. |
xmlpp::exception | If a new namespace node cannot be created, e.g. because a namespace with the same prefix but another URI already exists. |