libxml++ 2.35.3

- Main Page
- Related Pages
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Member Functions
xmlpp::Element Class Reference

Element nodes have attributes as well as child nodes. More...

`#include <libxml++/nodes/element.h>`

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

List of all members.

## Public Types

typedef std::list< Attribute* > | AttributeList

## Public Member Functions

| Element (_xmlNode* node)
virtual | ~Element ()
void | set_namespace_declaration (const Glib::ustring& ns_uri, const Glib::ustring& ns_prefix=Glib::ustring())
| This adds a namespace declaration to this node which will apply to this node and all children.
AttributeList | get_attributes ()
| Obtain the list of explicitly set attributes for this element.
const AttributeList | get_attributes () const
| Obtain the list of explicitly set attributes for this element.
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.
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.
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.
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.
TextNode* | get_child_text ()
| Get the first child text content node.
const TextNode* | get_child_text () const
| Get the first child text content node.
TextNode* | add_child_text (const Glib::ustring& content=Glib::ustring())
| Append a new text node.
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.
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.
void | set_child_text (const Glib::ustring& content)
| Set the text of the first text node, adding one if necessary.
bool | has_child_text () const
| Discover whether one of the child nodes is a text node.
CommentNode* | add_child_comment (const Glib::ustring& content)
| Append a new comment node.
CdataNode* | add_child_cdata (const Glib::ustring& content)
| Append a new CDATA node.
EntityReference* | add_child_entity_reference (const Glib::ustring& name)
| Append a new entity reference node.
ProcessingInstructionNode* | add_child_processing_instruction (const Glib::ustring& name, const Glib::ustring& content)
| Append a new processing instruction node.

## Protected Member Functions

Glib::ustring | get_namespace_uri_for_prefix (const Glib::ustring& ns_prefix) const

## Detailed Description

Element nodes have attributes as well as child nodes.

This will be instantiated by the parser.

## Member Typedef Documentation

typedef std::list<Attribute*> xmlpp::Element::AttributeList

## Constructor & Destructor Documentation

xmlpp::Element::Element | ( | _xmlNode * | node | ) | `[explicit]`

virtual xmlpp::Element::~Element | ( |  | ) | `[virtual]`

## Member Function Documentation

CdataNode* xmlpp::Element::add_child_cdata | ( | const Glib::ustring & | content | ) |

Append a new CDATA node.

Parameters:

  content | The raw text.

Returns:
  The new CDATA node.

CommentNode* xmlpp::Element::add_child_comment | ( | const Glib::ustring & | content | ) |

Append a new comment node.

Parameters:

  content | The text. This should be unescaped - see ContentNode::set_content().

Returns:
  The new comment node.

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.

Since libxml++ 2.36:

Parameters:

  name | The name of the entity.

Returns:
  The new entity reference node.

ProcessingInstructionNode* xmlpp::Element::add_child_processing_instruction | ( | const Glib::ustring & | name,
|  | const Glib::ustring & | content
| ) |  |

Append a new processing instruction node.

Since libxml++ 2.36:

Parameters:

  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().

Returns:
  The new processing instruction node.

TextNode* xmlpp::Element::add_child_text | ( | const Glib::ustring & | content = `Glib::ustring()` | ) |

Append a new text node.

Parameters:

  content | The text. This should be unescaped - see ContentNode::set_content().

Returns:
  The new text node.

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.

Since libxml++ 2.24:

Parameters:

  previous_sibling | An existing child node.
  content | The text. This should be unescaped - see ContentNode::set_content().

Returns:
  The new text node.

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.

Since libxml++ 2.24:

Parameters:

  next_sibling | An existing child node.
  content | The text. This should be unescaped - see ContentNode::set_content().

Returns:
  The new text node.

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.

Parameters:

  name | The name of the attribute that will be retrieved.
  ns_prefix | Namespace prefix.

Returns:
  The attribute, or 0 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.

Parameters:

  name | The name of the attribute whose value will be retrieved.
  ns_prefix | Namespace prefix.

Returns:
  The text value of the attribute, or an empty string if no such attribute was found.

Since libxml++ 2.20:

AttributeList xmlpp::Element::get_attributes | ( |  | ) |

Obtain the list of explicitly set attributes for this element.

Returns:
  The list of explicitly set attributes.

const AttributeList xmlpp::Element::get_attributes | ( |  | ) | const

Obtain the list of explicitly set attributes for this element.

Returns:
  The list of explicitly set attributes.

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.

Returns:
  The first text node, if any.

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.

Returns:
  The first text node, if any.

Glib::ustring xmlpp::Element::get_namespace_uri_for_prefix | ( | const Glib::ustring & | ns_prefix | ) | const`[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.

Returns:
  Whether this node has a child text node.

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.

Parameters:

  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.

Parameters:

  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.

Returns:
  The attribute that was changed, or 0 is no suitable Attribute was found.

Exceptions:

  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.

Parameters:

  content | The text. This should be unescaped - see ContentNode::set_content().

void xmlpp::Element::set_namespace_declaration | ( | const Glib::ustring & | ns_uri,
|  | const Glib::ustring & | ns_prefix = `Glib::ustring()`
| ) |  |

This adds a namespace declaration to this node which will apply to this node and all children.

Parameters:

  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.

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

- nodes/element.h