xmlwrapp
Lightweight C++ XML parsing library
|
Go to the documentation of this file.
40 #ifndef _xmlwrapp_node_h_
41 #define _xmlwrapp_node_h_
45 #include "xmlwrapp/export.h"
48 #include "xmlwrapp/_cbfo.h"
62 class const_nodes_view;
67 class iter_advance_functor;
72 struct xpath_context_impl;
151 explicit pi (
const char *name,
const char *content = NULL)
152 : n(name), c(content) {}
165 explicit text (
const char *content) : t(content) {}
179 explicit node(
const char *name);
190 node(
const char *name,
const char *content);
438 typedef int difference_type;
441 typedef std::forward_iterator_tag iterator_category;
458 impl::nipimpl *pimpl_;
461 void* get_raw_node()
const;
467 friend bool XMLWRAPP_API operator==(
const iterator& lhs,
const iterator& rhs);
481 typedef int difference_type;
484 typedef std::forward_iterator_tag iterator_category;
502 impl::nipimpl *pimpl_;
505 void* get_raw_node()
const;
834 void sort(
const char *node_name,
const char *attr_name);
843 template <
typename T>
void sort (T compare)
844 { impl::sort_callback<T> cb(compare); sort_fo(cb); }
861 {
xml = node_to_string(); }
870 friend XMLWRAPP_API std::ostream& operator<< (std::ostream &stream,
const node &n);
873 impl::node_impl *pimpl_;
878 void set_node_data(
void *data);
879 void* get_node_data();
880 void* release_node_data();
882 void sort_fo(impl::cbfo_node_compare &fo);
885 friend class impl::node_iterator;
887 friend struct impl::doc_impl;
888 friend struct impl::node_cmp;
890 friend struct impl::xpath_context_impl;
896 {
return lhs.get_raw_node() == rhs.get_raw_node(); }
897 inline bool operator!=(
const node::iterator& lhs,
const node::iterator& rhs)
898 {
return !(lhs == rhs); }
900 inline bool operator==(
const node::const_iterator& lhs,
const node::const_iterator& rhs)
901 {
return lhs.get_raw_node() == rhs.get_raw_node(); }
902 inline bool operator!=(
const node::const_iterator& lhs,
const node::const_iterator& rhs)
903 {
return !(lhs == rhs); }
907 #endif // _xmlwrapp_node_h_
const_nodes_view elements() const
Returns view of child nodes of type type_element.
Helper struct for creating a xml::node of type_cdata.
Definition: node.h:124
@ type_document
Document node.
Definition: node.h:105
This class implements a read-only view of XML nodes.
Definition: nodes_view.h:253
Helper struct for creating a xml::node of type_pi.
Definition: node.h:150
nodes_view elements()
Returns view of child nodes of type type_element.
iterator find(const char *name)
Find the first child node that has the given name.
void node_to_string(std::string &xml) const
Convert the node and all its children into XML text and set the given string to that text.
Definition: node.h:860
iterator begin()
Get an iterator that points to the beginning of this node's children.
node & operator=(const node &other)
Make this node equal to some other node via assignment.
@ type_entity
Entity as in &.
Definition: node.h:102
node(const char *name)
Construct a new xml::node and set the name of the node.
const char * get_content() const
Get the content for this text node.
size_type size() const
Returns the number of children this nodes has.
void swap(node &other)
Swap this node with another one.
@ type_cdata
text
Definition: node.h:99
node_type
enum for the different types of XML nodes
Definition: node.h:96
node(comment comment_info)
Construct a new xml::node that is of type_comment.
void sort(const char *node_name, const char *attr_name)
Sort all the children nodes of this node using one of their attributes.
@ type_document_type
DOCTYPE node.
Definition: node.h:106
const char * get_namespace() const
Get the namespace of this xml::node.
bool is_text() const
Find out if this node is a text node or something like a text node, CDATA for example.
node(pi pi_info)
Construct a new xml::node that is of type_pi.
iterator erase(iterator first, const iterator &last)
Erase all nodes in the given range, from first to last.
iterator parent()
Get an iterator that points at the parent of this node.
node(const char *name, const char *content)
Construct a new xml::node given a name and content.
iterator insert(const iterator &position, const node &n)
Insert a new child node.
nodes_view elements(const char *name)
Returns view of child nodes of type type_element with name name.
void move_under(node &new_parent)
Move this node under another parent.
const_iterator find(const char *name, const const_iterator &start) const
Find the first child node, starting with the given const_iterator, that has the given name.
void set_content(const char *content)
Set the content of a node.
@ type_document_frag
Document Fragment.
Definition: node.h:107
iterator find(const char *name, const iterator &start)
Find the first child node, starting with the given iterator, that has the given name.
node(const node &other)
Construct a new xml::node by copying another xml::node.
bool empty() const
Find out if this node has any children.
size_type erase(const char *name)
Erase all children nodes with the given name.
The xml::document class is used to hold the XML tree and various bits of information about it.
Definition: document.h:85
node_type get_type() const
Get this node's "type".
std::size_t size_type
size type
Definition: node.h:92
xml::attributes & get_attributes()
Get the list of attributes.
@ type_comment
XML comment.
Definition: node.h:101
void clear()
Erases all children nodes.
@ type_notation
Notation.
Definition: node.h:108
iterator erase(const iterator &to_erase)
Erase the node that is pointed to by the given iterator.
iterator end()
Get an iterator that points one past the last child for this node.
Definition: node.h:551
void push_back(const node &child)
Add a child xml::node to this node.
void set_text_content(const char *content)
Set the content of a node to given text.
const_iterator & operator++()
prefix increment
@ type_dtd_attribute
DTD <!ATTRLIST> node.
Definition: node.h:111
@ type_dtd
DTD node.
Definition: node.h:109
The xml::tree_parser class is used to parse an XML document and generate a tree like structure of xml...
Definition: tree_parser.h:74
@ type_text
Text node.
Definition: node.h:98
const char * get_name() const
Get the name of this xml::node.
Helper struct for creating a xml::node of type_text.
Definition: node.h:164
void sort(T compare)
Sort all the children nodes of this node using the given comparison function object.
Definition: node.h:843
@ type_entity_ref
Entity ref.
Definition: node.h:103
std::string node_to_string() const
Convert the node and all its children into XML text and return the string containing them.
@ type_pi
Processing Instruction.
Definition: node.h:100
const xml::attributes & get_attributes() const
Get the list of attributes.
XML library namespace.
Definition: attributes.h:52
node()
Construct a new blank xml::node.
@ type_xinclude
<xi:include/> node
Definition: node.h:104
void set_namespace(const std::string &href)
Set the default namespace of this xml::node.
const_iterator parent() const
Get a const_iterator that points at the parent of this node.
The xml::node::const_iterator provides a way to access children nodes similar to a standard C++ conta...
Definition: node.h:478
@ type_dtd_element
DTD <!ELEMENT> node.
Definition: node.h:110
@ type_dtd_entity
DTD <!ENTITY>
Definition: node.h:112
void set_name(const char *name)
Set the name of this xml::node.
iterator replace(const iterator &old_node, const node &new_node)
Replace the node pointed to by the given iterator with another node.
The xml::node class is used to hold information about one XML node.
Definition: node.h:89
The xml::node::iterator provides a way to access children nodes similar to a standard C++ container.
Definition: node.h:435
This class implements a view of XML nodes.
Definition: nodes_view.h:79
@ type_element
XML element such as "<chapter/>".
Definition: node.h:97
node(cdata cdata_info)
Construct a new xml::node that is of type_cdata.
node(text text_info)
Construct a new xml::node that is of type_text.
The xml::attributes class is used to access all the attributes of one xml::node.
Definition: attributes.h:72
const_nodes_view elements(const char *name) const
Returns view of child nodes of type type_element with name name.
iterator & operator++()
prefix increment
const_iterator find(const char *name) const
Find the first child node that has the given name.
iterator insert(const node &n)
Insert a new child node.
const_iterator end() const
Get a const_iterator that points one past the last child for this node.
Definition: node.h:559
const_iterator begin() const
Get a const_iterator that points to the beginning of this node's children.