libxml++ 1.0.0
xmlpp::Element Class Reference

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

Inherits xmlpp::Node.

List of all members.

Public Types

typedef std::list< Attribute * > AttributeList

Public Member Functions

 Element (_xmlNode *node)
virtual ~Element ()
void set_namespace_declaration (const std::string &ns_uri, const std::string &ns_prefix=std::string())
 This adds a namespace declaration to this node which will apply to this node and all children.
AttributeList get_attributes ()
 Obtain the list of attributes for this element.
const AttributeList get_attributes () const
 Obtain the list of attributes for this element.
Attributeget_attribute (const std::string &name, const std::string &ns_prefix=std::string()) const
Attributeset_attribute (const std::string &name, const std::string &value, const std::string &ns_prefix=std::string())
 Set the value of the attribute with this name, and optionally with this namespace.
void remove_attribute (const std::string &name, const std::string &ns_prefix=std::string())
 Remove the attribute with this name, and optionally with this namespace.
TextNodeget_child_text ()
 Get the first child text content node.
const TextNodeget_child_text () const
 Get the first child text content node.
TextNodeadd_child_text (const std::string &content=std::string())
 Append a new text node.
void set_child_text (const std::string &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.
CommentNodeadd_child_comment (const std::string &content)
 Append a new comment node.

Protected Member Functions

std::string get_namespace_uri_for_prefix (const std::string &ns_prefix) const

Detailed Description

Element nodes have attributes as well as child nodes.

This will be instantiated by the parser.


Member Typedef Documentation


Constructor & Destructor Documentation

xmlpp::Element::Element ( _xmlNode *  node) [explicit]
virtual xmlpp::Element::~Element ( ) [virtual]

Member Function Documentation

CommentNode* xmlpp::Element::add_child_comment ( const std::string &  content)

Append a new comment node.

Parameters:
contentThe text. This should be unescaped - see ContentNode::set_content().
Returns:
The new comment node.
TextNode* xmlpp::Element::add_child_text ( const std::string &  content = std::string())

Append a new text node.

Parameters:
contentThe text. This should be unescaped - see ContentNode::set_content().
Returns:
The new text node.
Attribute* xmlpp::Element::get_attribute ( const std::string &  name,
const std::string &  ns_prefix = std::string() 
) const
AttributeList xmlpp::Element::get_attributes ( )

Obtain the list of attributes for this element.

Returns:
The list of attributes.
const AttributeList xmlpp::Element::get_attributes ( ) const

Obtain the list of attributes for this element.

Returns:
The list of 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.
std::string xmlpp::Element::get_namespace_uri_for_prefix ( const std::string &  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 std::string &  name,
const std::string &  ns_prefix = std::string() 
)

Remove the attribute with this name, and optionally with this namespace.

Parameters:
nameThe name of the attribute to be removed
ns_prefixNamespace prefix. If specified, the attribute will be removed only if the attribute has this namespace.
Attribute* xmlpp::Element::set_attribute ( const std::string &  name,
const std::string &  value,
const std::string &  ns_prefix = std::string() 
)

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:
nameThe name of the attribute whose value will change.
valueThe new value for the attribute
ns_prefixNamespace 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.
void xmlpp::Element::set_child_text ( const std::string &  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:
contentThe text. This should be unescaped - see ContentNode::set_content().
void xmlpp::Element::set_namespace_declaration ( const std::string &  ns_uri,
const std::string &  ns_prefix = std::string() 
)

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

Parameters:
ns_uriThe namespace to associate with the prefix, or to use as the default namespace if no prefix is specified.
ns_prefixThe 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: