xmlwrapp
Lightweight C++ XML parsing library
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 *content) : t(content) {}
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  Note that this is only a forward iterator.
433  */
434  class iterator
435  {
436  public:
437  typedef node value_type;
438  typedef int difference_type;
439  typedef value_type* pointer;
440  typedef value_type& reference;
441  typedef std::forward_iterator_tag iterator_category;
442 
443  iterator() : pimpl_(0) {}
444  iterator(const iterator& other);
445  iterator& operator=(const iterator& other);
446  ~iterator();
447 
448  reference operator* () const;
449  pointer operator->() const;
450 
451  /// prefix increment
452  iterator& operator++();
453 
454  /// postfix increment (avoid if possible for better performance)
455  iterator operator++ (int);
456 
457  private:
458  impl::nipimpl *pimpl_;
459 
460  explicit iterator (void *data);
461  void* get_raw_node() const;
462  void swap (iterator &other);
463 
464  friend class node;
465  friend class document;
466  friend class const_iterator;
467  friend bool XMLWRAPP_API operator==(const iterator& lhs, const iterator& rhs);
468  };
469 
470  /**
471  The xml::node::const_iterator provides a way to access children nodes
472  similar to a standard C++ container. The nodes that are pointed to by
473  the const_iterator cannot be changed.
474 
475  Note that this is only a forward iterator.
476  */
478  {
479  public:
480  typedef const node value_type;
481  typedef int difference_type;
482  typedef value_type* pointer;
483  typedef value_type& reference;
484  typedef std::forward_iterator_tag iterator_category;
485 
486  const_iterator() : pimpl_(0) {}
487  const_iterator(const const_iterator &other);
488  const_iterator(const iterator &other);
489  const_iterator& operator=(const const_iterator& other);
490  ~const_iterator();
491 
492  reference operator* () const;
493  pointer operator->() const;
494 
495  /// prefix increment
496  const_iterator& operator++();
497 
498  /// postfix increment (avoid if possible for better performance)
499  const_iterator operator++ (int);
500 
501  private:
502  impl::nipimpl *pimpl_;
503 
504  explicit const_iterator (void *data);
505  void* get_raw_node() const;
506  void swap (const_iterator &other);
507 
508  friend class document;
509  friend class node;
510  friend bool XMLWRAPP_API operator==(const const_iterator& lhs, const const_iterator& rhs);
511  };
512 
513  /**
514  Returns the number of children this nodes has. If you just want to
515  know how if this node has children or not, you should use
516  xml::node::empty() instead.
517 
518  @return The number of children this node has.
519  */
520  size_type size() const;
521 
522  /**
523  Find out if this node has any children. This is the same as
524  xml::node::size() == 0 except it is much faster.
525 
526  @return True if this node DOES NOT have any children.
527  @return False if this node does have children.
528  */
529  bool empty() const;
530 
531  /**
532  Get an iterator that points to the beginning of this node's children.
533 
534  @return An iterator that points to the beginning of the children.
535  */
536  iterator begin();
537 
538  /**
539  Get a const_iterator that points to the beginning of this node's
540  children.
541 
542  @return A const_iterator that points to the beginning of the children.
543  */
544  const_iterator begin() const;
545 
546  /**
547  Get an iterator that points one past the last child for this node.
548 
549  @return A "one past the end" iterator.
550  */
551  iterator end() { return iterator(); }
552 
553  /**
554  Get a const_iterator that points one past the last child for this
555  node.
556 
557  @return A "one past the end" const_iterator
558  */
559  const_iterator end() const { return const_iterator(); }
560 
561  /**
562  Get an iterator that points back at this node.
563 
564  @return An iterator that points at this node.
565  */
566  iterator self();
567 
568  /**
569  Get a const_iterator that points back at this node.
570 
571  @return A const_iterator that points at this node.
572  */
573  const_iterator self() const;
574 
575  /**
576  Get an iterator that points at the parent of this node. If this node
577  does not have a parent, this member function will return an "end"
578  iterator.
579 
580  @return An iterator that points to this nodes parent.
581  @return If no parent, returns the same iterator that xml::node::end() returns.
582  */
583  iterator parent();
584 
585  /**
586  Get a const_iterator that points at the parent of this node. If this
587  node does not have a parent, this member function will return an
588  "end" const_iterator.
589 
590  @return A const_iterator that points to this nodes parent.
591  @return If no parent, returns the same const_iterator that xml::node::end() returns.
592  */
593  const_iterator parent() const;
594 
595  /**
596  Find the first child node that has the given name. If no such node
597  can be found, this function will return the same iterator that end()
598  would return.
599 
600  This function is not recursive. That is, it will not search down the
601  tree for the requested node. Instead, it will only search one level
602  deep, only checking the children of this node.
603 
604  @param name The name of the node you want to find.
605  @return An iterator that points to the node if found.
606  @return An end() iterator if the node was not found.
607 
608  @see elements(const char*), find(const char*, iterator)
609  */
610  iterator find(const char *name);
611 
612  /**
613  Find the first child node that has the given name. If no such node
614  can be found, this function will return the same const_iterator that
615  end() would return.
616 
617  This function is not recursive. That is, it will not search down the
618  tree for the requested node. Instead, it will only search one level
619  deep, only checking the children of this node.
620 
621  @param name The name of the node you want to find.
622  @return A const_iterator that points to the node if found.
623  @return An end() const_iterator if the node was not found.
624 
625  @see elements(const char*) const,
626  find(const char*, const_iterator) const
627  */
628  const_iterator find(const char *name) const;
629 
630  /**
631  Find the first child node, starting with the given iterator, that has
632  the given name. If no such node can be found, this function will
633  return the same iterator that end() would return.
634 
635  This function should be given an iterator to one of this node's
636  children. The search will begin with that node and continue with all
637  its sibliings. This function will not recurse down the tree, it only
638  searches in one level.
639 
640  @param name The name of the node you want to find.
641  @param start Where to begin the search.
642  @return An iterator that points to the node if found.
643  @return An end() iterator if the node was not found.
644 
645  @see elements(const char*)
646  */
647  iterator find(const char *name, const iterator& start);
648 
649  /**
650  Find the first child node, starting with the given const_iterator,
651  that has the given name. If no such node can be found, this function
652  will return the same const_iterator that end() would return.
653 
654  This function should be given a const_iterator to one of this node's
655  children. The search will begin with that node and continue with all
656  its siblings. This function will not recurse down the tree, it only
657  searches in one level.
658 
659  @param name The name of the node you want to find.
660  @param start Where to begin the search.
661  @return A const_iterator that points to the node if found.
662  @return An end() const_iterator if the node was not found.
663 
664  @see elements(const char*) const
665  */
666  const_iterator find(const char *name, const const_iterator& start) const;
667 
668  /**
669  Returns view of child nodes of type type_element. If no such node
670  can be found, returns empty view.
671 
672  Example:
673  @code
674  xml::nodes_view view(root.elements());
675  for (xml::nodes_view::iterator i = view.begin(); i != view.end(); ++i)
676  {
677  ...
678  }
679  @endcode
680 
681  @return View with all child elements or empty view if there aren't any.
682  @since 0.6.0
683 
684  @see nodes_view
685  */
686  nodes_view elements();
687 
688  /**
689  Returns view of child nodes of type type_element. If no such node
690  can be found, returns empty view.
691 
692  Example:
693  @code
694  xml::const_nodes_view view(root.elements());
695  for (xml::const_nodes_view::const_iterator i = view.begin();
696  i != view.end();
697  ++i)
698  {
699  ...
700  }
701  @endcode
702 
703  @return View with all child elements or empty view if there aren't any.
704  @since 0.6.0
705 
706  @see const_nodes_view
707  */
708  const_nodes_view elements() const;
709 
710  /**
711  Returns view of child nodes of type type_element with name @a name.
712  If no such node can be found, returns empty view.
713 
714  Example:
715  @code
716  xml::nodes_view view(root.elements("person"));
717  for (xml::nodes_view::iterator i = view.begin(); i != view.end(); ++i)
718  {
719  ...
720  }
721  @endcode
722 
723  @param name Name of the elements to return.
724  @return View that contains only elements @a name.
725  @since 0.6.0
726  */
727  nodes_view elements(const char *name);
728 
729  /**
730  Returns view of child nodes of type type_element with name @a name.
731  If no such node can be found, returns empty view.
732 
733  Example:
734  @code
735  xml::const_nodes_view view(root.elements("person"));
736  for (xml::const_nodes_view::const_iterator i = view.begin();
737  i != view.end();
738  ++i)
739  {
740  ...
741  }
742  @endcode
743 
744  @param name Name of the elements to return.
745  @return View that contains only elements @a name.
746  @since 0.6.0
747  */
748  const_nodes_view elements(const char *name) const;
749 
750  /**
751  Insert a new child node. The new node will be inserted at the end of
752  the child list. This is similar to the xml::node::push_back member
753  function except that an iterator to the inserted node is returned.
754 
755  @param n The node to insert as a child of this node.
756  @return An iterator that points to the newly inserted node.
757  */
758  iterator insert(const node& n);
759 
760  /**
761  Insert a new child node. The new node will be inserted before the
762  node pointed to by the given iterator.
763 
764  @param position An iterator that points to the location where the new node should be inserted (before it).
765  @param n The node to insert as a child of this node.
766  @return An iterator that points to the newly inserted node.
767  */
768  iterator insert(const iterator& position, const node& n);
769 
770  /**
771  Replace the node pointed to by the given iterator with another node.
772  The old node will be removed, including all its children, and
773  replaced with the new node. This will invalidate any iterators that
774  point to the node to be replaced, or any pointers or references to
775  that node.
776 
777  @param old_node An iterator that points to the node that should be removed.
778  @param new_node The node to put in old_node's place.
779  @return An iterator that points to the new node.
780  */
781  iterator replace(const iterator& old_node, const node& new_node);
782 
783  /**
784  Erase the node that is pointed to by the given iterator. The node
785  and all its children will be removed from this node. This will
786  invalidate any iterators that point to the node to be erased, or any
787  pointers or references to that node.
788 
789  @param to_erase An iterator that points to the node to be erased.
790  @return An iterator that points to the node after the one being erased.
791  */
792  iterator erase(const iterator& to_erase);
793 
794  /**
795  Erase all nodes in the given range, from first to last. This will
796  invalidate any iterators that point to the nodes to be erased, or any
797  pointers or references to those nodes.
798 
799  @param first The first node in the range to be removed.
800  @param last An iterator that points one past the last node to erase. Think xml::node::end().
801  @return An iterator that points to the node after the last one being erased.
802  */
803  iterator erase(iterator first, const iterator& last);
804 
805  /**
806  Erase all children nodes with the given name. This will find all
807  nodes that have the given node name and remove them from this node.
808  This will invalidate any iterators that point to the nodes to be
809  erased, or any pointers or references to those nodes.
810 
811  @param name The name of nodes to remove.
812  @return The number of nodes removed.
813  */
814  size_type erase(const char *name);
815 
816  /**
817  Erases all children nodes.
818 
819  @since 0.7.0
820  */
821  void clear();
822 
823  /**
824  Sort all the children nodes of this node using one of their
825  attributes. Only nodes that are of xml::node::type_element will be
826  sorted, and they must have the given node_name.
827 
828  The sorting is done by calling std::strcmp on the value of the given
829  attribute.
830 
831  @param node_name The name of the nodes to sort.
832  @param attr_name The attribute to sort on.
833  */
834  void sort(const char *node_name, const char *attr_name);
835 
836  /**
837  Sort all the children nodes of this node using the given comparison
838  function object. All element type nodes will be considered for
839  sorting.
840 
841  @param compare The binary function object to call in order to sort all child nodes.
842  */
843  template <typename T> void sort (T compare)
844  { impl::sort_callback<T> cb(compare); sort_fo(cb); }
845 
846  /**
847  Convert the node and all its children into XML text and return the
848  string containing them.
849 
850  @since 0.8.0
851  */
852  std::string node_to_string() const;
853 
854  /**
855  Convert the node and all its children into XML text and set the given
856  string to that text.
857 
858  @param xml The string to set the node's XML data to.
859  */
860  void node_to_string(std::string& xml) const
861  { xml = node_to_string(); }
862 
863  /**
864  Write a node and all of its children to the given stream.
865 
866  @param stream The stream to write the node as XML.
867  @param n The node to write to the stream.
868  @return The stream.
869  */
870  friend XMLWRAPP_API std::ostream& operator<< (std::ostream &stream, const node &n);
871 
872 private:
873  impl::node_impl *pimpl_;
874 
875  // private ctor to create uninitialized instance
876  explicit node(int);
877 
878  void set_node_data(void *data);
879  void* get_node_data();
880  void* release_node_data();
881 
882  void sort_fo(impl::cbfo_node_compare &fo);
883 
884  friend class tree_parser;
885  friend class impl::node_iterator;
886  friend class document;
887  friend struct impl::doc_impl;
888  friend struct impl::node_cmp;
889  friend class xml::const_nodes_view;
890  friend struct impl::xpath_context_impl;
891 };
892 
893 // Comparison operators for xml::node iterators
894 
895 inline bool XMLWRAPP_API operator==(const node::iterator& lhs,
896  const node::iterator& rhs)
897  { return lhs.get_raw_node() == rhs.get_raw_node(); }
898 inline bool XMLWRAPP_API operator!=(const node::iterator& lhs,
899  const node::iterator& rhs)
900  { return !(lhs == rhs); }
901 
902 inline bool XMLWRAPP_API operator==(const node::const_iterator& lhs,
903  const node::const_iterator& rhs)
904  { return lhs.get_raw_node() == rhs.get_raw_node(); }
905 inline bool XMLWRAPP_API operator!=(const node::const_iterator& lhs,
906  const node::const_iterator& rhs)
907  { return !(lhs == rhs); }
908 
909 } // namespace xml
910 
911 #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 "<chapter/>".
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
<![CDATA[text]]>
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 &amp;.
Definition: node.h:102
Document node.
Definition: node.h:105
node_type
enum for the different types of XML nodes
Definition: node.h:95
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:84
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:434
Notation.
Definition: node.h:108
XML library namespace.
Definition: attributes.h:51
Processing Instruction.
Definition: node.h:100
DTD <!ELEMENT> node.
Definition: node.h:110
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:551
<xi:include/> node
Definition: node.h:104
DTD <!ATTRLIST> 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:477
Document Fragment.
Definition: node.h:107
DTD <!ENTITY>
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
const_iterator end() const
Get a const_iterator that points one past the last child for this node.
Definition: node.h:559
void sort(T compare)
Sort all the children nodes of this node using the given comparison function object.
Definition: node.h:843
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