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