Scopira  20080306
scopira::tool::xml_node Class Reference

#include <xml.h>

Public Types

enum  { element_c = XML_ELEMENT_NODE, text_c = XML_TEXT_NODE }
 iterator-filter types
 

Public Member Functions

 xml_node (void)
 
 xml_node (xmlNodePtr ptr)
 
xmlNodePtr get_ptr (void) const
 returns the internal pointer – use with care
 
int get_type (void) const
 
const char * get_c_name (void) const
 
std::string get_name (void) const
 
const char * get_c_content (void) const
 
bool is_null (void) const
 
bool is_valid (void) const
 
void next (void)
 
void next_type (int typ)
 
void next_name (const std::string &name)
 
int count_children (const std::string &name) const
 
xml_node get_first_child (void) const
 
xml_node get_first_child_type (int typ) const
 
xml_node get_first_child_name (const std::string &name) const
 
xml_attrib get_first_attrib (void) const
 
const char * get_attrib_c_text (const std::string &aname) const
 
const char * get_child_c_text (const std::string &nname) const
 
bool has_attrib (const std::string &aname) const
 
xml_node add_child (const std::string &name)
 
xml_node add_comment (const std::string &comment_contents)
 
void clear_this (void)
 
void add_attrib (const std::string &key, const std::string &val)
 
xml_node add_content_child (const std::string &content)
 
void clear_content_children (void)
 
const char * get_text_c_content (void) const
 
const char * get_leaf_text_content (const std::string &pathnodespec) const
 
void load_string_attrib (const std::string &name, std::string &outval)
 
template<class I >
void children_load_xml (const std::string &elementname, I iter) const
 
template<class I >
void children_load_attrib (const std::string &elementname, const std::string &attribname, I iter) const
 
template<class I >
void children_load_text (const std::string &elementname, I iter) const
 

Detailed Description

A pointer/link to a NODE within an existing XML document. This is an ultra light, full copyable, non-virtual class.

Author
Aleksander Demko

Constructor & Destructor Documentation

◆ xml_node() [1/2]

scopira::tool::xml_node::xml_node ( void  )
inline

Null pointer constructor

Author
Aleksander Demko

◆ xml_node() [2/2]

scopira::tool::xml_node::xml_node ( xmlNodePtr  ptr)
inlineexplicit

Initialization constructor

Author
Aleksander Demko

Member Function Documentation

◆ add_attrib()

void scopira::tool::xml_node::add_attrib ( const std::string &  key,
const std::string &  val 
)

Sets/adds the given attribute and value

Author
Aleksander Demko

◆ add_child()

xml_node scopira::tool::xml_node::add_child ( const std::string &  name)

Adds a new child node with the given name and return it

Author
Aleksander Demko

◆ add_comment()

xml_node scopira::tool::xml_node::add_comment ( const std::string &  comment_contents)

Adds a comment to this node and returns it.

Author
Aleksander Demko

◆ add_content_child()

xml_node scopira::tool::xml_node::add_content_child ( const std::string &  content)

Adds the given content/text block to this node

Author
Aleksander Demko

◆ children_load_attrib()

template<class I >
void scopira::tool::xml_node::children_load_attrib ( const std::string &  elementname,
const std::string &  attribname,
iter 
) const
inline

Loads attributes from all the sub elements in the iteration

Author
Aleksander Demko

References is_valid().

◆ children_load_text()

template<class I >
void scopira::tool::xml_node::children_load_text ( const std::string &  elementname,
iter 
) const
inline

Loads texts/content blocks from all the sub elementname in the iteration

Author
Aleksander Demko

References is_valid().

◆ children_load_xml()

template<class I >
void scopira::tool::xml_node::children_load_xml ( const std::string &  elementname,
iter 
) const
inline

Applies load_xml to all the sub elements in the iteration.

Author
Aleksander Demko

References is_valid().

◆ clear_content_children()

void scopira::tool::xml_node::clear_content_children ( void  )

Remove any and all text sub nodes from this node.

Author
Aleksander Demko

◆ clear_this()

void scopira::tool::xml_node::clear_this ( void  )

Removes THIS node from the parent and deletes itself. After this call, THIS node is no longer valid.

Author
Aleksander Demko

◆ count_children()

int scopira::tool::xml_node::count_children ( const std::string &  name) const

Counts the number of children nodes with the given name

Author
Aleksander Demko

◆ get_attrib_c_text()

const char* scopira::tool::xml_node::get_attrib_c_text ( const std::string &  aname) const

Super helper. Return the full attrib value of the given key.

Returns "" on not found.

Author
Aleksander Demko

◆ get_c_content()

const char* scopira::tool::xml_node::get_c_content ( void  ) const
inline

Gets the text of this node, as a C string. This may return null!

Author
Aleksander Demko

◆ get_c_name()

const char* scopira::tool::xml_node::get_c_name ( void  ) const
inline

Gets the name of this node, (C) string

Author
Aleksander Demko

◆ get_child_c_text()

const char* scopira::tool::xml_node::get_child_c_text ( const std::string &  nname) const

Super helper. Returns the full c_area of the SUB node with the given name.

Returns "" on any and all errors.

Author
Aleksander Demko

◆ get_first_attrib()

xml_attrib scopira::tool::xml_node::get_first_attrib ( void  ) const

Gets the first attribute of this node

Author
Aleksander Demko

◆ get_first_child()

xml_node scopira::tool::xml_node::get_first_child ( void  ) const
inline

Get the first child node May return an empty node.

Author
Aleksander Demko

◆ get_first_child_name()

xml_node scopira::tool::xml_node::get_first_child_name ( const std::string &  name) const

Get the first child node with the given name May return an empty node.

Author
Aleksander Demko

◆ get_first_child_type()

xml_node scopira::tool::xml_node::get_first_child_type ( int  typ) const

Get the first child node with the given type May return an empty node.

Author
Aleksander Demko

◆ get_leaf_text_content()

const char* scopira::tool::xml_node::get_leaf_text_content ( const std::string &  pathnodespec) const

Gets the first text/content block's text.

This is a convience verion, that allows you to drill down into sub nodes, using / in the names. It never returns null or fails, but will return empty string if it can't find a particular node.

Examples: "blah" "leafnode/nodename" "subnode/leafnode/nodename"

Author
Aleksander Demko

◆ get_name()

std::string scopira::tool::xml_node::get_name ( void  ) const
inline

Gets the name of this node

Author
Aleksander Demko

◆ get_text_c_content()

const char* scopira::tool::xml_node::get_text_c_content ( void  ) const

Gets the first text/content block's text. If this node has no text blocks, an empty (but otherwise valid) string will be returned. Never returns null when the node itself is valid.

Author
Aleksander Demko

◆ get_type()

int scopira::tool::xml_node::get_type ( void  ) const
inline

Gets the node type

Author
Aleksander Demko

◆ has_attrib()

bool scopira::tool::xml_node::has_attrib ( const std::string &  aname) const

Does this node have an attribute with the given name?

Author
Aleksander Demko

◆ is_null()

bool scopira::tool::xml_node::is_null ( void  ) const
inline

Is this an empty node?

Author
Aleksander Demko

◆ is_valid()

bool scopira::tool::xml_node::is_valid ( void  ) const
inline

Is this node not-empty (valid)?

Author
Aleksander Demko

Referenced by children_load_attrib(), children_load_text(), and children_load_xml().

◆ load_string_attrib()

void scopira::tool::xml_node::load_string_attrib ( const std::string &  name,
std::string &  outval 
)

Loads the given attribute. outval will be set to "" if the given attribute could not be found.

Author
Aleksander Demko

◆ next()

void scopira::tool::xml_node::next ( void  )
inline

Advance this node to the next node in the list

Author
Aleksander Demko

◆ next_name()

void scopira::tool::xml_node::next_name ( const std::string &  name)

Advance this node to the next node in the list that has the given name

Author
Aleksander Demko

◆ next_type()

void scopira::tool::xml_node::next_type ( int  typ)

Advance this node to the next node in the list that has the given type

Author
Aleksander Demko

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