xmlwrapp
Lightweight C++ XML parsing library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
node.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org)
3  * 2009 Vaclav Slavik <vslavik@gmail.com>
4  * All Rights Reserved
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * 3. Neither the name of the Author nor the names of its contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
24  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 /**
35  @file
36 
37  This file contains the definition of the xml::node class.
38  */
39 
40 #ifndef _xmlwrapp_node_h_
41 #define _xmlwrapp_node_h_
42 
43 // xmlwrapp includes
44 #include "xmlwrapp/init.h"
45 #include "xmlwrapp/export.h"
46 
47 // hidden stuff
48 #include "xmlwrapp/_cbfo.h"
49 
50 // standard includes
51 #include <cstddef>
52 #include <iosfwd>
53 #include <string>
54 
55 namespace xml
56 {
57 
58 // forward declarations
59 class document;
60 class attributes;
61 class nodes_view;
62 class const_nodes_view;
63 
64 namespace impl
65 {
66 class node_iterator;
67 class iter_advance_functor;
68 struct node_impl;
69 struct doc_impl;
70 struct nipimpl;
71 struct node_cmp;
72 struct xpath_context_impl;
73 }
74 
75 
76 /**
77  The xml::node class is used to hold information about one XML node.
78 
79  This includes the name of the node, the namespace of the node and
80  attributes for the node. It also has an iterator whereby you can get to the
81  children nodes.
82 
83  It should be noted that any member function that returns a const char*
84  returns a temporary value. The pointer that is returned will change with
85  ANY operation to the xml::node. If you need the data to stick around a
86  little longer you should put it inside a std::string.
87  */
88 class XMLWRAPP_API node
89 {
90 public:
91  /// size type
92  typedef std::size_t size_type;
93 
94  /// enum for the different types of XML nodes
95  enum node_type
96  {
97  type_element, ///< XML element such as "<chapter/>"
98  type_text, ///< Text node
99  type_cdata, ///< <![CDATA[text]]>
100  type_pi, ///< Processing Instruction
101  type_comment, ///< XML comment
102  type_entity, ///< Entity as in &amp;amp;
103  type_entity_ref, ///< Entity ref
104  type_xinclude, ///< <xi:include/> node
105  type_document, ///< Document node
106  type_document_type, ///< DOCTYPE node
107  type_document_frag, ///< Document Fragment
108  type_notation, ///< Notation
109  type_dtd, ///< DTD node
110  type_dtd_element, ///< DTD <!ELEMENT> node
111  type_dtd_attribute, ///< DTD <!ATTRLIST> node
112  type_dtd_entity, ///< DTD <!ENTITY>
113  type_dtd_namespace ///< ?
114  };
115 
116  /**
117  Helper struct for creating a xml::node of type_cdata.
118 
119  @code
120  xml::node mynode(xml::node::cdata("This is a CDATA section"));
121  @endcode
122  */
123  struct cdata
124  {
125  explicit cdata(const char *text) : t(text) {}
126  const char *t;
127  };
128 
129  /**
130  Helper struct for creating a xml::node of type_comment.
131 
132  @code
133  xml::node mynode(xml::node::comment("This is an XML comment"));
134  @endcode
135  */
136  struct comment
137  {
138  explicit comment (const char *text) : t(text) {}
139  const char *t;
140  };
141 
142  /**
143  Helper struct for creating a xml::node of type_pi.
144 
145  @code
146  xml::node mynode(xml::node::pi("xslt", "stylesheet=\"test.xsl\""));
147  @endcode
148  */
149  struct pi
150  {
151  explicit pi (const char *name, const char *content = NULL)
152  : n(name), c(content) {}
153  const char *n, *c;
154  };
155 
156  /**
157  Helper struct for creating a xml::node of type_text.
158 
159  @code
160  xml::node mynode(xml::node::text("This is an XML text fragment"));
161  @endcode
162  */
163  struct text
164  {
165  explicit text (const char *text) : t(text) {}
166  const char *t;
167  };
168 
169  /**
170  Construct a new blank xml::node.
171  */
172  node();
173 
174  /**
175  Construct a new xml::node and set the name of the node.
176 
177  @param name The name of the new node.
178  */
179  explicit node(const char *name);
180 
181  /**
182  Construct a new xml::node given a name and content.
183 
184  The content, if it's not an empty string, will be used to create a new
185  child text node.
186 
187  @param name The name of the new element.
188  @param content The text that will be used to create a child node.
189  */
190  node(const char *name, const char *content);
191 
192  /**
193  Construct a new xml::node that is of type_cdata. The cdata_info
194  parameter should contain the contents of the CDATA section.
195 
196  @note Sample Use Example:
197  @code
198  xml::node mynode(xml::node::cdata("This is a CDATA section"));
199  @endcode
200 
201  @param cdata_info A cdata struct that tells xml::node what the
202  content will be.
203  */
204  explicit node(cdata cdata_info);
205 
206  /**
207  Construct a new xml::node that is of type_comment. The comment_info
208  parameter should contain the contents of the XML comment.
209 
210  @note Sample Use Example:
211  @code
212  xml::node mynode(xml::node::comment("This is an XML comment"));
213  @endcode
214 
215  @param comment_info A comment struct that tells xml::node what the comment will be.
216  */
217  explicit node(comment comment_info);
218 
219  /**
220  Construct a new xml::node that is of type_pi. The pi_info parameter
221  should contain the name of the XML processing instruction (PI), and
222  optionally, the contents of the XML PI.
223 
224  @note Sample Use Example:
225  @code
226  xml::node mynode(xml::node::pi("xslt", "stylesheet=\"test.xsl\""));
227  @endcode
228 
229  @param pi_info A pi struct that tells xml::node what the name and contents of the XML PI are.
230  */
231  explicit node(pi pi_info);
232 
233  /**
234  Construct a new xml::node that is of type_text. The text_info
235  parameter should contain the text.
236 
237  @note Sample Use Example:
238  @code
239  xml::node mynode(xml::node::text("This is XML text"));
240  @endcode
241 
242  @param text_info A text struct that tells xml::node what the text will be.
243  */
244  explicit node(text text_info);
245 
246  /**
247  Construct a new xml::node by copying another xml::node.
248 
249  @param other The other node to copy.
250  */
251  node(const node& other);
252 
253  /**
254  Make this node equal to some other node via assignment.
255 
256  @param other The other node to copy.
257  @return A reference to this node.
258  */
259  node& operator=(const node& other);
260 
261  /**
262  Class destructor
263  */
264  ~node();
265 
266  /**
267  Set the name of this xml::node.
268 
269  @param name The new name for this xml::node.
270  */
271  void set_name(const char *name);
272 
273  /**
274  Get the name of this xml::node.
275 
276  This function may change in the future to return std::string.
277  Feedback is welcome.
278 
279  @return The name of this node.
280  */
281  const char* get_name() const;
282 
283  /**
284  Set the content of a node. If this node is an element node, this
285  function will remove all of its children nodes and replace them
286  with one text node set to the given string.
287 
288  @param content The content of the text node.
289 
290  @note @a content is supposed to be a piece of XML CDATA, so it allows
291  entity references, but XML special chars need to be escaped
292  first. In particular, the '&' character @em must be escaped
293  as "&amp;" unless it's part of entity reference. Not escaping
294  @a content may result in truncation of data. Use
295  set_text_content() if @a content may contain special characters.
296 
297  @see set_text_content()
298  */
299  void set_content(const char *content);
300 
301  /**
302  Set the content of a node to given text.
303 
304  In contrast to set_content(), @a content is raw text, so unescaped XML
305  special chars are allowed and entity references are not supported.
306 
307  If this node is an element node, this function will remove all of its
308  children nodes and replace them with one text node set to the given
309  string.
310 
311  @param content The content text.
312 
313  @see set_content()
314 
315  @since 0.7.0
316  */
317  void set_text_content(const char *content);
318 
319  /**
320  Get the content for this text node. If this node is not a text node
321  but it has children nodes that are text nodes, the contents of those
322  child nodes will be returned. If there is no content or these
323  conditions do not apply, zero will be returned.
324 
325  This function may change in the future to return std::string.
326  Feedback is welcome.
327 
328  @return The content or 0.
329  */
330  const char* get_content() const;
331 
332  /**
333  Get this node's "type". You can use that information to know what you
334  can and cannot do with it.
335 
336  @return The node's type.
337  */
338  node_type get_type() const;
339 
340  /**
341  Get the list of attributes. You can use the returned object to get
342  and set the attributes for this node. Make sure you use a reference
343  to this returned object, to prevent a copy.
344 
345  @return The xml::attributes object for this node.
346  */
347  xml::attributes& get_attributes();
348 
349  /**
350  Get the list of attributes. You can use the returned object to get
351  the attributes for this node. Make sure you use a reference to this
352  returned object, to prevent a copy.
353 
354  @return The xml::attributes object for this node.
355  */
356  const xml::attributes& get_attributes() const;
357 
358  /**
359  Get the namespace of this xml::node.
360 
361  @return The namespace of this node or NULL if no namespace is
362  associated.
363  @since 0.6.0
364  */
365  const char* get_namespace() const;
366 
367  /**
368  Set the default namespace of this xml::node.
369 
370  If the default namespace is already set on this node, it is changed.
371 
372  Example:
373 
374  @code
375  // n is <foo/>
376  n.set_namespace("http://example.com")
377  // n is <foo xmlns="http://example.com"/>
378  @endcode
379 
380  @since 0.8.0
381  */
382  void set_namespace(const std::string& href);
383 
384  /**
385  Find out if this node is a text node or something like a text node,
386  CDATA for example.
387 
388  @return True if this node is a text node; false otherwise.
389  */
390  bool is_text() const;
391 
392  /**
393  Add a child xml::node to this node.
394 
395  @param child The child xml::node to add.
396  */
397  void push_back(const node& child);
398 
399  /**
400  Swap this node with another one.
401 
402  @param other The other node to swap with.
403  */
404  void swap(node& other);
405 
406  /**
407  Move this node under another parent.
408 
409  This node will become the last child of @a new_parent. Notice that this
410  node must not be an ancestor of @a new_parent, in particular it
411  shouldn't be the document root.
412 
413  Currently this method can only be used to move nodes inside the same
414  document.
415 
416  All iterators pointing to this node are invalidated after the move.
417 
418  @param new_parent The new parent for the node.
419 
420  @since 0.8.0
421  */
422  void move_under(node& new_parent);
423 
424 
425  class const_iterator; // forward declaration
426 
427  /**
428  The xml::node::iterator provides a way to access children nodes
429  similar to a standard C++ container. The nodes that are pointed to by
430  the iterator can be changed.
431  */
432  class iterator
433  {
434  public:
435  typedef node value_type;
436  typedef int difference_type;
437  typedef value_type* pointer;
438  typedef value_type& reference;
439  typedef std::forward_iterator_tag iterator_category;
440 
441  iterator() : pimpl_(0) {}
442  iterator(const iterator& other);
443  iterator& operator=(const iterator& other);
444  ~iterator();
445 
446  reference operator* () const;
447  pointer operator->() const;
448 
449  /// prefix increment
450  iterator& operator++();
451 
452  /// postfix increment (avoid if possible for better performance)
453  iterator operator++ (int);
454 
455  private:
456  impl::nipimpl *pimpl_;
457 
458  explicit iterator (void *data);
459  void* get_raw_node() const;
460  void swap (iterator &other);
461 
462  friend class node;
463  friend class document;
464  friend class const_iterator;
465  friend bool XMLWRAPP_API operator==(const iterator& lhs, const iterator& rhs);
466  };
467 
468  /**
469  The xml::node::const_iterator provides a way to access children nodes
470  similar to a standard C++ container. The nodes that are pointed to by
471  the const_iterator cannot be changed.
472  */
474  {
475  public:
476  typedef const node value_type;
477  typedef int difference_type;
478  typedef value_type* pointer;
479  typedef value_type& reference;
480  typedef std::forward_iterator_tag iterator_category;
481 
482  const_iterator() : pimpl_(0) {}
483  const_iterator(const const_iterator &other);
484  const_iterator(const iterator &other);
485  const_iterator& operator=(const const_iterator& other);
486  ~const_iterator();
487 
488  reference operator* () const;
489  pointer operator->() const;
490 
491  /// prefix increment
492  const_iterator& operator++();
493 
494  /// postfix increment (avoid if possible for better performance)
495  const_iterator operator++ (int);
496 
497  private:
498  impl::nipimpl *pimpl_;
499 
500  explicit const_iterator (void *data);
501  void* get_raw_node() const;
502  void swap (const_iterator &other);
503 
504  friend class document;
505  friend class node;
506  friend bool XMLWRAPP_API operator==(const const_iterator& lhs, const const_iterator& rhs);
507  };
508 
509  /**
510  Returns the number of children this nodes has. If you just want to
511  know how if this node has children or not, you should use
512  xml::node::empty() instead.
513 
514  @return The number of children this node has.
515  */
516  size_type size() const;
517 
518  /**
519  Find out if this node has any children. This is the same as
520  xml::node::size() == 0 except it is much faster.
521 
522  @return True if this node DOES NOT have any children.
523  @return False if this node does have children.
524  */
525  bool empty() const;
526 
527  /**
528  Get an iterator that points to the beginning of this node's children.
529 
530  @return An iterator that points to the beginning of the children.
531  */
532  iterator begin();
533 
534  /**
535  Get a const_iterator that points to the beginning of this node's
536  children.
537 
538  @return A const_iterator that points to the beginning of the children.
539  */
540  const_iterator begin() const;
541 
542  /**
543  Get an iterator that points one past the last child for this node.
544 
545  @return A "one past the end" iterator.
546  */
547  iterator end() { return iterator(); }
548 
549  /**
550  Get a const_iterator that points one past the last child for this
551  node.
552 
553  @return A "one past the end" const_iterator
554  */
555  const_iterator end() const { return const_iterator(); }
556 
557  /**
558  Get an iterator that points back at this node.
559 
560  @return An iterator that points at this node.
561  */
562  iterator self();
563 
564  /**
565  Get a const_iterator that points back at this node.
566 
567  @return A const_iterator that points at this node.
568  */
569  const_iterator self() const;
570 
571  /**
572  Get an iterator that points at the parent of this node. If this node
573  does not have a parent, this member function will return an "end"
574  iterator.
575 
576  @return An iterator that points to this nodes parent.
577  @return If no parent, returns the same iterator that xml::node::end() returns.
578  */
579  iterator parent();
580 
581  /**
582  Get a const_iterator that points at the parent of this node. If this
583  node does not have a parent, this member function will return an
584  "end" const_iterator.
585 
586  @return A const_iterator that points to this nodes parent.
587  @return If no parent, returns the same const_iterator that xml::node::end() returns.
588  */
589  const_iterator parent() const;
590 
591  /**
592  Find the first child node that has the given name. If no such node
593  can be found, this function will return the same iterator that end()
594  would return.
595 
596  This function is not recursive. That is, it will not search down the
597  tree for the requested node. Instead, it will only search one level
598  deep, only checking the children of this node.
599 
600  @param name The name of the node you want to find.
601  @return An iterator that points to the node if found.
602  @return An end() iterator if the node was not found.
603 
604  @see elements(const char*), find(const char*, iterator)
605  */
606  iterator find(const char *name);
607 
608  /**
609  Find the first child node that has the given name. If no such node
610  can be found, this function will return the same const_iterator that
611  end() would return.
612 
613  This function is not recursive. That is, it will not search down the
614  tree for the requested node. Instead, it will only search one level
615  deep, only checking the children of this node.
616 
617  @param name The name of the node you want to find.
618  @return A const_iterator that points to the node if found.
619  @return An end() const_iterator if the node was not found.
620 
621  @see elements(const char*) const,
622  find(const char*, const_iterator) const
623  */
624  const_iterator find(const char *name) const;
625 
626  /**
627  Find the first child node, starting with the given iterator, that has
628  the given name. If no such node can be found, this function will
629  return the same iterator that end() would return.
630 
631  This function should be given an iterator to one of this node's
632  children. The search will begin with that node and continue with all
633  its sibliings. This function will not recurse down the tree, it only
634  searches in one level.
635 
636  @param name The name of the node you want to find.
637  @param start Where to begin the search.
638  @return An iterator that points to the node if found.
639  @return An end() iterator if the node was not found.
640 
641  @see elements(const char*)
642  */
643  iterator find(const char *name, const iterator& start);
644 
645  /**
646  Find the first child node, starting with the given const_iterator,
647  that has the given name. If no such node can be found, this function
648  will return the same const_iterator that end() would return.
649 
650  This function should be given a const_iterator to one of this node's
651  children. The search will begin with that node and continue with all
652  its siblings. This function will not recurse down the tree, it only
653  searches in one level.
654 
655  @param name The name of the node you want to find.
656  @param start Where to begin the search.
657  @return A const_iterator that points to the node if found.
658  @return An end() const_iterator if the node was not found.
659 
660  @see elements(const char*) const
661  */
662  const_iterator find(const char *name, const const_iterator& start) const;
663 
664  /**
665  Returns view of child nodes of type type_element. If no such node
666  can be found, returns empty view.
667 
668  Example:
669  @code
670  xml::nodes_view view(root.elements());
671  for (xml::nodes_view::iterator i = view.begin(); i != view.end(); ++i)
672  {
673  ...
674  }
675  @endcode
676 
677  @return View with all child elements or empty view if there aren't any.
678  @since 0.6.0
679 
680  @see nodes_view
681  */
682  nodes_view elements();
683 
684  /**
685  Returns view of child nodes of type type_element. If no such node
686  can be found, returns empty view.
687 
688  Example:
689  @code
690  xml::const_nodes_view view(root.elements());
691  for (xml::const_nodes_view::const_iterator i = view.begin();
692  i != view.end();
693  ++i)
694  {
695  ...
696  }
697  @endcode
698 
699  @return View with all child elements or empty view if there aren't any.
700  @since 0.6.0
701 
702  @see const_nodes_view
703  */
704  const_nodes_view elements() const;
705 
706  /**
707  Returns view of child nodes of type type_element with name @a name.
708  If no such node can be found, returns empty view.
709 
710  Example:
711  @code
712  xml::nodes_view view(root.elements("person"));
713  for (xml::nodes_view::iterator i = view.begin(); i != view.end(); ++i)
714  {
715  ...
716  }
717  @endcode
718 
719  @param name Name of the elements to return.
720  @return View that contains only elements @a name.
721  @since 0.6.0
722  */
723  nodes_view elements(const char *name);
724 
725  /**
726  Returns view of child nodes of type type_element with name @a name.
727  If no such node can be found, returns empty view.
728 
729  Example:
730  @code
731  xml::const_nodes_view view(root.elements("person"));
732  for (xml::const_nodes_view::const_iterator i = view.begin();
733  i != view.end();
734  ++i)
735  {
736  ...
737  }
738  @endcode
739 
740  @param name Name of the elements to return.
741  @return View that contains only elements @a name.
742  @since 0.6.0
743  */
744  const_nodes_view elements(const char *name) const;
745 
746  /**
747  Insert a new child node. The new node will be inserted at the end of
748  the child list. This is similar to the xml::node::push_back member
749  function except that an iterator to the inserted node is returned.
750 
751  @param n The node to insert as a child of this node.
752  @return An iterator that points to the newly inserted node.
753  */
754  iterator insert(const node& n);
755 
756  /**
757  Insert a new child node. The new node will be inserted before the
758  node pointed to by the given iterator.
759 
760  @param position An iterator that points to the location where the new node should be inserted (before it).
761  @param n The node to insert as a child of this node.
762  @return An iterator that points to the newly inserted node.
763  */
764  iterator insert(const iterator& position, const node& n);
765 
766  /**
767  Replace the node pointed to by the given iterator with another node.
768  The old node will be removed, including all its children, and
769  replaced with the new node. This will invalidate any iterators that
770  point to the node to be replaced, or any pointers or references to
771  that node.
772 
773  @param old_node An iterator that points to the node that should be removed.
774  @param new_node The node to put in old_node's place.
775  @return An iterator that points to the new node.
776  */
777  iterator replace(const iterator& old_node, const node& new_node);
778 
779  /**
780  Erase the node that is pointed to by the given iterator. The node
781  and all its children will be removed from this node. This will
782  invalidate any iterators that point to the node to be erased, or any
783  pointers or references to that node.
784 
785  @param to_erase An iterator that points to the node to be erased.
786  @return An iterator that points to the node after the one being erased.
787  */
788  iterator erase(const iterator& to_erase);
789 
790  /**
791  Erase all nodes in the given range, from first to last. This will
792  invalidate any iterators that point to the nodes to be erased, or any
793  pointers or references to those nodes.
794 
795  @param first The first node in the range to be removed.
796  @param last An iterator that points one past the last node to erase. Think xml::node::end().
797  @return An iterator that points to the node after the last one being erased.
798  */
799  iterator erase(iterator first, const iterator& last);
800 
801  /**
802  Erase all children nodes with the given name. This will find all
803  nodes that have the given node name and remove them from this node.
804  This will invalidate any iterators that point to the nodes to be
805  erased, or any pointers or references to those nodes.
806 
807  @param name The name of nodes to remove.
808  @return The number of nodes removed.
809  */
810  size_type erase(const char *name);
811 
812  /**
813  Erases all children nodes.
814 
815  @since 0.7.0
816  */
817  void clear();
818 
819  /**
820  Sort all the children nodes of this node using one of their
821  attributes. Only nodes that are of xml::node::type_element will be
822  sorted, and they must have the given node_name.
823 
824  The sorting is done by calling std::strcmp on the value of the given
825  attribute.
826 
827  @param node_name The name of the nodes to sort.
828  @param attr_name The attribute to sort on.
829  */
830  void sort(const char *node_name, const char *attr_name);
831 
832  /**
833  Sort all the children nodes of this node using the given comparison
834  function object. All element type nodes will be considered for
835  sorting.
836 
837  @param compare The binary function object to call in order to sort all child nodes.
838  */
839  template <typename T> void sort (T compare)
840  { impl::sort_callback<T> cb(compare); sort_fo(cb); }
841 
842  /**
843  Convert the node and all its children into XML text and return the
844  string containing them.
845 
846  @since 0.8.0
847  */
848  std::string node_to_string() const;
849 
850  /**
851  Convert the node and all its children into XML text and set the given
852  string to that text.
853 
854  @param xml The string to set the node's XML data to.
855  */
856  void node_to_string(std::string& xml) const
857  { xml = node_to_string(); }
858 
859  /**
860  Write a node and all of its children to the given stream.
861 
862  @param stream The stream to write the node as XML.
863  @param n The node to write to the stream.
864  @return The stream.
865  */
866  friend XMLWRAPP_API std::ostream& operator<< (std::ostream &stream, const node &n);
867 
868 private:
869  impl::node_impl *pimpl_;
870 
871  // private ctor to create uninitialized instance
872  explicit node(int);
873 
874  void set_node_data(void *data);
875  void* get_node_data();
876  void* release_node_data();
877 
878  void sort_fo(impl::cbfo_node_compare &fo);
879 
880  friend class tree_parser;
881  friend class impl::node_iterator;
882  friend class document;
883  friend struct impl::doc_impl;
884  friend struct impl::node_cmp;
885  friend class xml::const_nodes_view;
886  friend struct impl::xpath_context_impl;
887 };
888 
889 // Comparison operators for xml::node iterators
890 
891 inline bool XMLWRAPP_API operator==(const node::iterator& lhs,
892  const node::iterator& rhs)
893  { return lhs.get_raw_node() == rhs.get_raw_node(); }
894 inline bool XMLWRAPP_API operator!=(const node::iterator& lhs,
895  const node::iterator& rhs)
896  { return !(lhs == rhs); }
897 
898 inline bool XMLWRAPP_API operator==(const node::const_iterator& lhs,
899  const node::const_iterator& rhs)
900  { return lhs.get_raw_node() == rhs.get_raw_node(); }
901 inline bool XMLWRAPP_API operator!=(const node::const_iterator& lhs,
902  const node::const_iterator& rhs)
903  { return !(lhs == rhs); }
904 
905 } // namespace xml
906 
907 #endif // _xmlwrapp_node_h_
The xml::tree_parser class is used to parse an XML document and generate a tree like structure of xml...
Definition: tree_parser.h:73
XML element such as "".
Definition: node.h:97
Helper struct for creating a xml::node of type_pi.
Definition: node.h:149
This file contains the definition of the xml::init class.
Helper struct for creating a xml::node of type_comment.
Definition: node.h:136
Definition: node.h:99
Helper struct for creating a xml::node of type_cdata.
Definition: node.h:123
DOCTYPE node.
Definition: node.h:106
Entity as in &.
Definition: node.h:102
Document node.
Definition: node.h:105
node_type
enum for the different types of XML nodes
Definition: node.h:95
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:856
This class implements a read-only view of XML nodes.
Definition: nodes_view.h:252
The xml::document class is used to hold the XML tree and various bits of information about it...
Definition: document.h:83
XML comment.
Definition: node.h:101
The xml::node::iterator provides a way to access children nodes similar to a standard C++ container...
Definition: node.h:432
Notation.
Definition: node.h:108
XML library namespace.
Definition: attributes.h:51
Processing Instruction.
Definition: node.h:100
DTD node.
Definition: node.h:110
const_iterator end() const
Get a const_iterator that points one past the last child for this node.
Definition: node.h:555
The xml::node class is used to hold information about one XML node.
Definition: node.h:88
The xml::attributes class is used to access all the attributes of one xml::node.
Definition: attributes.h:71
DTD node.
Definition: node.h:109
iterator end()
Get an iterator that points one past the last child for this node.
Definition: node.h:547
node
Definition: node.h:104
DTD node.
Definition: node.h:111
std::size_t size_type
size type
Definition: node.h:92
Entity ref.
Definition: node.h:103
The xml::node::const_iterator provides a way to access children nodes similar to a standard C++ conta...
Definition: node.h:473
Document Fragment.
Definition: node.h:107
DTD
Definition: node.h:112
This class implements a view of XML nodes.
Definition: nodes_view.h:78
Helper struct for creating a xml::node of type_text.
Definition: node.h:163
Text node.
Definition: node.h:98
void sort(T compare)
Sort all the children nodes of this node using the given comparison function object.
Definition: node.h:839