40#ifndef _xmlwrapp_node_h_
41#define _xmlwrapp_node_h_
45#include "xmlwrapp/export.h"
48#include "xmlwrapp/_cbfo.h"
56XMLWRAPP_MSVC_SUPPRESS_DLL_MEMBER_WARN
65class const_nodes_view;
70class iter_advance_functor;
75struct xpath_context_impl;
154 explicit pi (
const char *name,
const char *content =
nullptr)
155 : n(name), c(content) {}
168 explicit text (
const char *content) : t(content) {}
182 explicit node(
const char *name);
193 node(
const char *name,
const char *content);
450 using difference_type = int;
453 using iterator_category = std::forward_iterator_tag;
470 std::unique_ptr<impl::nipimpl> pimpl_;
473 void* get_raw_node()
const;
479 friend bool XMLWRAPP_API operator==(
const iterator& lhs,
const iterator& rhs);
493 using difference_type = int;
496 using iterator_category = std::forward_iterator_tag;
514 std::unique_ptr<impl::nipimpl> pimpl_;
517 void* get_raw_node()
const;
839 void sort(
const char *node_name,
const char *attr_name);
848 template <
typename T>
void sort (T compare)
849 { impl::sort_callback<T> cb(compare); sort_fo(cb); }
866 {
xml = node_to_string(); }
875 friend XMLWRAPP_API std::ostream& operator<< (std::ostream &stream,
const node &n);
878 std::unique_ptr<impl::node_impl> pimpl_;
883 void set_node_data(
void *data);
884 void* get_node_data();
885 void* release_node_data();
887 void sort_fo(impl::cbfo_node_compare &fo);
890 friend class impl::node_iterator;
892 friend struct impl::doc_impl;
893 friend struct impl::node_cmp;
895 friend struct impl::xpath_context_impl;
901 {
return lhs.get_raw_node() == rhs.get_raw_node(); }
902inline bool operator!=(
const node::iterator& lhs,
const node::iterator& rhs)
903 {
return !(lhs == rhs); }
905inline bool operator==(
const node::const_iterator& lhs,
const node::const_iterator& rhs)
906 {
return lhs.get_raw_node() == rhs.get_raw_node(); }
907inline bool operator!=(
const node::const_iterator& lhs,
const node::const_iterator& rhs)
908 {
return !(lhs == rhs); }
912XMLWRAPP_MSVC_RESTORE_DLL_MEMBER_WARN
The xml::attributes class is used to access all the attributes of one xml::node.
Definition attributes.h:75
This class implements a read-only view of XML nodes.
Definition nodes_view.h:256
The xml::document class is used to hold the XML tree and various bits of information about it.
Definition document.h:88
The xml::node::const_iterator provides a way to access children nodes similar to a standard C++ conta...
Definition node.h:490
const_iterator & operator++()
prefix increment
The xml::node::iterator provides a way to access children nodes similar to a standard C++ container.
Definition node.h:447
iterator & operator++()
prefix increment
The xml::node class is used to hold information about one XML node.
Definition node.h:92
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.
void sort(T compare)
Sort all the children nodes of this node using the given comparison function object.
Definition node.h:848
iterator insert(const iterator &position, const node &n)
Insert a new child node.
iterator begin()
Get an iterator that points to the beginning of this node's children.
void clear()
Erases all children nodes.
const_iterator parent() const
Get a const_iterator that points at the parent of this node.
const char * get_content() const
Get the content for this text node.
const_iterator find(const char *name) const
Find the first child node that has the given name.
node()
Construct a new blank xml::node.
node & operator=(const node &other)
Make this node equal to some other node via assignment.
size_type size() const
Returns the number of children this nodes has.
std::string node_to_string() const
Convert the node and all its children into XML text and return the string containing them.
const_nodes_view elements() const
Returns view of child nodes of type type_element.
bool empty() const
Find out if this node has any children.
node(const char *name)
Construct a new xml::node and set the name of the node.
node(const char *name, const char *content)
Construct a new xml::node given a name and content.
node_type get_type() const
Get this node's "type".
iterator erase(iterator first, const iterator &last)
Erase all nodes in the given range, from first to last.
void push_back(const node &child)
Add a child xml::node to this node.
node(const node &other)
Construct a new xml::node by copying another xml::node.
const_iterator self() const
Get a const_iterator that points back at this node.
iterator end()
Get an iterator that points one past the last child for this node.
Definition node.h:563
node_type
enum for the different types of XML nodes
Definition node.h:99
@ type_element
XML element such as "<chapter/>".
Definition node.h:100
@ type_xinclude
<xi:include/> node
Definition node.h:107
@ type_notation
Notation.
Definition node.h:111
@ type_document_frag
Document Fragment.
Definition node.h:110
@ type_document_type
DOCTYPE node.
Definition node.h:109
@ type_dtd_element
DTD <!ELEMENT> node.
Definition node.h:113
@ type_document
Document node.
Definition node.h:108
@ type_comment
XML comment.
Definition node.h:104
@ type_dtd_entity
DTD <!ENTITY>
Definition node.h:115
@ type_dtd
DTD node.
Definition node.h:112
@ type_cdata
text
Definition node.h:102
@ type_text
Text node.
Definition node.h:101
@ type_entity
Entity as in &.
Definition node.h:105
@ type_entity_ref
Entity ref.
Definition node.h:106
@ type_pi
Processing Instruction.
Definition node.h:103
@ type_dtd_attribute
DTD <!ATTRLIST> node.
Definition node.h:114
iterator find(const char *name)
Find the first child node that has the given name.
const char * get_namespace() const
Get the namespace of this xml::node.
const_iterator end() const
Get a const_iterator that points one past the last child for this node.
Definition node.h:571
nodes_view elements()
Returns view of child nodes of type type_element.
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:865
bool is_text() const
Find out if this node is a text node or something like a text node, CDATA for example.
iterator parent()
Get an iterator that points at the parent of this node.
iterator find(const char *name, const iterator &start)
Find the first child node, starting with the given iterator, that has the given name.
node(comment comment_info)
Construct a new xml::node that is of type_comment.
const_iterator begin() const
Get a const_iterator that points to the beginning of this node's children.
node(pi pi_info)
Construct a new xml::node that is of type_pi.
node(text text_info)
Construct a new xml::node that is of type_text.
const xml::attributes & get_attributes() const
Get the list of attributes.
void set_content(const char *content)
Set the content of a node.
xml::attributes & get_attributes()
Get the list of attributes.
size_type erase(const char *name)
Erase all children nodes with the given name.
void set_namespace(const std::string &href)
Set the namespace of this xml::node and its children.
iterator self()
Get an iterator that points back at this node.
nodes_view elements(const char *name)
Returns view of child nodes of type type_element with name name.
const_nodes_view elements(const char *name) const
Returns view of child nodes of type type_element with name name.
node(cdata cdata_info)
Construct a new xml::node that is of type_cdata.
iterator insert(const node &n)
Insert a new child node.
void swap(node &other)
Swap this node with another one.
std::size_t size_type
size type
Definition node.h:95
void move_under(node &new_parent)
Move this node under another parent.
const char * get_name() const
Get the name of this xml::node.
void sort(const char *node_name, const char *attr_name)
Sort all the children nodes of this node using one of their attributes.
iterator erase(const iterator &to_erase)
Erase the node that is pointed to by the given iterator.
void set_text_content(const char *content)
Set the content of a node to given text.
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.
This class implements a view of XML nodes.
Definition nodes_view.h:82
The xml::tree_parser class is used to parse an XML document and generate a tree like structure of xml...
Definition tree_parser.h:77
XML library namespace.
Definition attributes.h:55
Helper struct for creating a xml::node of type_cdata.
Definition node.h:127
Helper struct for creating a xml::node of type_pi.
Definition node.h:153
Helper struct for creating a xml::node of type_text.
Definition node.h:167
This file contains the definition of the xml::init class.