Open
Graph Drawing
Framework

 v. 2025.10-dev (Foxglove)
 

Loading...
Searching...
No Matches
pugixml.h
Go to the documentation of this file.
1
14// Define version macro; evaluates to major * 1000 + minor * 10 + patch so that it's safe to use in less-than comparisons
15// Note: pugixml used major * 100 + minor * 10 + patch format up until 1.9 (which had version identifier 190); starting from pugixml 1.10, the minor version number is two digits
16#ifndef PUGIXML_VERSION
17# define PUGIXML_VERSION 1150 // 1.15
18#endif
19
20// Include user configuration file (this can define various configuration macros)
21#include "pugiconfig.h"
22
23#ifndef HEADER_PUGIXML_HPP
24#define HEADER_PUGIXML_HPP
25
26// Include stddef.h for size_t and ptrdiff_t
27#include <stddef.h>
28
29// Include exception header for XPath
30#if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
31# include <exception>
32#endif
33
34// Include STL headers
35#ifndef PUGIXML_NO_STL
36# include <iterator>
37# include <iosfwd>
38# include <string>
39#endif
40
41// Check if std::string_view is available
42#if !defined(PUGIXML_HAS_STRING_VIEW) && !defined(PUGIXML_NO_STL)
43# if __cplusplus >= 201703L
44# define PUGIXML_HAS_STRING_VIEW
45# elif defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
46# define PUGIXML_HAS_STRING_VIEW
47# endif
48#endif
49
50// Include string_view if appropriate
51#ifdef PUGIXML_HAS_STRING_VIEW
52# include <string_view>
53#endif
54
55// Macro for deprecated features
56#ifndef PUGIXML_DEPRECATED
57# if defined(__GNUC__)
58# define PUGIXML_DEPRECATED __attribute__((deprecated))
59# elif defined(_MSC_VER) && _MSC_VER >= 1300
60# define PUGIXML_DEPRECATED __declspec(deprecated)
61# else
62# define PUGIXML_DEPRECATED
63# endif
64#endif
65
66// If no API is defined, assume default
67#ifndef PUGIXML_API
68# define PUGIXML_API
69#endif
70
71// If no API for classes is defined, assume default
72#ifndef PUGIXML_CLASS
73# define PUGIXML_CLASS PUGIXML_API
74#endif
75
76// If no API for functions is defined, assume default
77#ifndef PUGIXML_FUNCTION
78# define PUGIXML_FUNCTION PUGIXML_API
79#endif
80
81// If the platform is known to have long long support, enable long long functions
82#ifndef PUGIXML_HAS_LONG_LONG
83# if __cplusplus >= 201103
84# define PUGIXML_HAS_LONG_LONG
85# elif defined(_MSC_VER) && _MSC_VER >= 1400
86# define PUGIXML_HAS_LONG_LONG
87# endif
88#endif
89
90// If the platform is known to have move semantics support, compile move ctor/operator implementation
91#ifndef PUGIXML_HAS_MOVE
92# if __cplusplus >= 201103
93# define PUGIXML_HAS_MOVE
94# elif defined(_MSC_VER) && _MSC_VER >= 1600
95# define PUGIXML_HAS_MOVE
96# endif
97#endif
98
99// If C++ is 2011 or higher, use 'noexcept' specifiers
100#ifndef PUGIXML_NOEXCEPT
101# if __cplusplus >= 201103
102# define PUGIXML_NOEXCEPT noexcept
103# elif defined(_MSC_VER) && _MSC_VER >= 1900
104# define PUGIXML_NOEXCEPT noexcept
105# else
106# define PUGIXML_NOEXCEPT throw()
107# endif
108#endif
109
110// Some functions can not be noexcept in compact mode
111#ifdef PUGIXML_COMPACT
112# define PUGIXML_NOEXCEPT_IF_NOT_COMPACT
113#else
114# define PUGIXML_NOEXCEPT_IF_NOT_COMPACT PUGIXML_NOEXCEPT
115#endif
116
117// If C++ is 2011 or higher, add 'override' qualifiers
118#ifndef PUGIXML_OVERRIDE
119# if __cplusplus >= 201103
120# define PUGIXML_OVERRIDE override
121# elif defined(_MSC_VER) && _MSC_VER >= 1700
122# define PUGIXML_OVERRIDE override
123# else
124# define PUGIXML_OVERRIDE
125# endif
126#endif
127
128// If C++ is 2011 or higher, use 'nullptr'
129#ifndef PUGIXML_NULL
130# if __cplusplus >= 201103
131# define PUGIXML_NULL nullptr
132# elif defined(_MSC_VER) && _MSC_VER >= 1600
133# define PUGIXML_NULL nullptr
134# else
135# define PUGIXML_NULL 0
136# endif
137#endif
138
139// Character interface macros
140#ifdef PUGIXML_WCHAR_MODE
141# define PUGIXML_TEXT(t) L ## t
142# define PUGIXML_CHAR wchar_t
143#else
144# define PUGIXML_TEXT(t) t
145# define PUGIXML_CHAR char
146#endif
147
148namespace pugi
149{
150 // Character type used for all internal storage and operations; depends on PUGIXML_WCHAR_MODE
152
153#ifndef PUGIXML_NO_STL
154 // String type used for operations that work with STL string; depends on PUGIXML_WCHAR_MODE
155 typedef std::basic_string<PUGIXML_CHAR> string_t;
156#endif
157
158#ifdef PUGIXML_HAS_STRING_VIEW
159 // String view type used for operations that can work with a length delimited string; depends on PUGIXML_WCHAR_MODE
160 typedef std::basic_string_view<PUGIXML_CHAR> string_view_t;
161#endif
162}
163
164// The PugiXML namespace
165namespace pugi
166{
167 // Tree node types
169 {
170 node_null, // Empty (null) node handle
171 node_document, // A document tree's absolute root
172 node_element, // Element tag, i.e. '<node/>'
173 node_pcdata, // Plain character data, i.e. 'text'
174 node_cdata, // Character data, i.e. '<![CDATA[text]]>'
175 node_comment, // Comment tag, i.e. '<!-- text -->'
176 node_pi, // Processing instruction, i.e. '<?name?>'
177 node_declaration, // Document declaration, i.e. '<?xml version="1.0"?>'
178 node_doctype // Document type declaration, i.e. '<!DOCTYPE doc>'
179 };
180
181 // Parsing options
182
183 // Minimal parsing mode (equivalent to turning all other flags off).
184 // Only elements and PCDATA sections are added to the DOM tree, no text conversions are performed.
185 const unsigned int parse_minimal = 0x0000;
186
187 // This flag determines if processing instructions (node_pi) are added to the DOM tree. This flag is off by default.
188 const unsigned int parse_pi = 0x0001;
189
190 // This flag determines if comments (node_comment) are added to the DOM tree. This flag is off by default.
191 const unsigned int parse_comments = 0x0002;
192
193 // This flag determines if CDATA sections (node_cdata) are added to the DOM tree. This flag is on by default.
194 const unsigned int parse_cdata = 0x0004;
195
196 // This flag determines if plain character data (node_pcdata) that consist only of whitespace are added to the DOM tree.
197 // This flag is off by default; turning it on usually results in slower parsing and more memory consumption.
198 const unsigned int parse_ws_pcdata = 0x0008;
199
200 // This flag determines if character and entity references are expanded during parsing. This flag is on by default.
201 const unsigned int parse_escapes = 0x0010;
202
203 // This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default.
204 const unsigned int parse_eol = 0x0020;
205
206 // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. This flag is on by default.
207 const unsigned int parse_wconv_attribute = 0x0040;
208
209 // This flag determines if attribute values are normalized using NMTOKENS normalization rules during parsing. This flag is off by default.
210 const unsigned int parse_wnorm_attribute = 0x0080;
211
212 // This flag determines if document declaration (node_declaration) is added to the DOM tree. This flag is off by default.
213 const unsigned int parse_declaration = 0x0100;
214
215 // This flag determines if document type declaration (node_doctype) is added to the DOM tree. This flag is off by default.
216 const unsigned int parse_doctype = 0x0200;
217
218 // This flag determines if plain character data (node_pcdata) that is the only child of the parent node and that consists only
219 // of whitespace is added to the DOM tree.
220 // This flag is off by default; turning it on may result in slower parsing and more memory consumption.
221 const unsigned int parse_ws_pcdata_single = 0x0400;
222
223 // This flag determines if leading and trailing whitespace is to be removed from plain character data. This flag is off by default.
224 const unsigned int parse_trim_pcdata = 0x0800;
225
226 // This flag determines if plain character data that does not have a parent node is added to the DOM tree, and if an empty document
227 // is a valid document. This flag is off by default.
228 const unsigned int parse_fragment = 0x1000;
229
230 // This flag determines if plain character data is be stored in the parent element's value. This significantly changes the structure of
231 // the document; this flag is only recommended for parsing documents with many PCDATA nodes in memory-constrained environments.
232 // This flag is off by default.
233 const unsigned int parse_embed_pcdata = 0x2000;
234
235 // This flag determines whether determines whether the the two pcdata should be merged or not, if no intermediatory data are parsed in the document.
236 // This flag is off by default.
237 const unsigned int parse_merge_pcdata = 0x4000;
238
239 // The default parsing mode.
240 // Elements, PCDATA and CDATA sections are added to the DOM tree, character/reference entities are expanded,
241 // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.
243
244 // The full parsing mode.
245 // Nodes of all types are added to the DOM tree, character/reference entities are expanded,
246 // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.
248
249 // These flags determine the encoding of input data for XML document
251 {
252 encoding_auto, // Auto-detect input encoding using BOM or < / <? detection; use UTF8 if BOM is not found
253 encoding_utf8, // UTF8 encoding
254 encoding_utf16_le, // Little-endian UTF16
255 encoding_utf16_be, // Big-endian UTF16
256 encoding_utf16, // UTF16 with native endianness
257 encoding_utf32_le, // Little-endian UTF32
258 encoding_utf32_be, // Big-endian UTF32
259 encoding_utf32, // UTF32 with native endianness
260 encoding_wchar, // The same encoding wchar_t has (either UTF16 or UTF32)
262 };
263
264 // Formatting flags
265
266 // Indent the nodes that are written to output stream with as many indentation strings as deep the node is in DOM tree. This flag is on by default.
267 const unsigned int format_indent = 0x01;
268
269 // Write encoding-specific BOM to the output stream. This flag is off by default.
270 const unsigned int format_write_bom = 0x02;
271
272 // Use raw output mode (no indentation and no line breaks are written). This flag is off by default.
273 const unsigned int format_raw = 0x04;
274
275 // Omit default XML declaration even if there is no declaration in the document. This flag is off by default.
276 const unsigned int format_no_declaration = 0x08;
277
278 // Don't escape attribute values and PCDATA contents. This flag is off by default.
279 const unsigned int format_no_escapes = 0x10;
280
281 // Open file using text mode in xml_document::save_file. This enables special character (i.e. new-line) conversions on some systems. This flag is off by default.
282 const unsigned int format_save_file_text = 0x20;
283
284 // Write every attribute on a new line with appropriate indentation. This flag is off by default.
285 const unsigned int format_indent_attributes = 0x40;
286
287 // Don't output empty element tags, instead writing an explicit start and end tag even if there are no children. This flag is off by default.
288 const unsigned int format_no_empty_element_tags = 0x80;
289
290 // Skip characters belonging to range [0; 32) instead of "&#xNN;" encoding. This flag is off by default.
291 const unsigned int format_skip_control_chars = 0x100;
292
293 // Use single quotes ' instead of double quotes " for enclosing attribute values. This flag is off by default.
294 const unsigned int format_attribute_single_quote = 0x200;
295
296 // The default set of formatting flags.
297 // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none.
298 const unsigned int format_default = format_indent;
299
302
303 // Forward declarations
304 struct xml_attribute_struct;
305 struct xml_node_struct;
306
307 class xml_node_iterator;
310
311 class xml_tree_walker;
312
313 struct xml_parse_result;
314
315 class xml_node;
316
317 class xml_text;
318
319 #ifndef PUGIXML_NO_XPATH
320 class xpath_node;
321 class xpath_node_set;
322 class xpath_query;
323 class xpath_variable_set;
324 #endif
325
326 // Range-based for loop support
327 template <typename It> class xml_object_range
328 {
329 public:
330 typedef It const_iterator;
331 typedef It iterator;
332
333 xml_object_range(It b, It e): _begin(b), _end(e)
334 {
335 }
336
337 It begin() const { return _begin; }
338 It end() const { return _end; }
339
340 bool empty() const { return _begin == _end; }
341
342 private:
344 };
345
346 // Writer interface for node printing (see xml_node::print)
348 {
349 public:
350 virtual ~xml_writer();
351
352 // Write memory chunk into stream/file/whatever
353 virtual void write(const void* data, size_t size) = 0;
354 };
355
356 // xml_writer implementation for FILE*
358 {
359 public:
360 // Construct writer from a FILE* object; void* is used to avoid header dependencies on stdio
361 xml_writer_file(void* file);
362
363 virtual void write(const void* data, size_t size) PUGIXML_OVERRIDE;
364
365 private:
366 void* file;
367 };
368
369 #ifndef PUGIXML_NO_STL
370 // xml_writer implementation for streams
372 {
373 public:
374 // Construct writer from an output stream object
375 xml_writer_stream(std::basic_ostream<char>& stream);
376 xml_writer_stream(std::basic_ostream<wchar_t>& stream);
377
378 virtual void write(const void* data, size_t size) PUGIXML_OVERRIDE;
379
380 private:
381 std::basic_ostream<char>* narrow_stream;
382 std::basic_ostream<wchar_t>* wide_stream;
383 };
384 #endif
385
386 // A light-weight handle for manipulating attributes in DOM tree
388 {
390 friend class xml_node;
391
392 private:
393 xml_attribute_struct* _attr;
394
395 typedef void (*unspecified_bool_type)(xml_attribute***);
396
397 public:
398 // Default constructor. Constructs an empty attribute.
400
401 // Constructs attribute from internal pointer
402 explicit xml_attribute(xml_attribute_struct* attr);
403
404 // Safe bool conversion operator
405 operator unspecified_bool_type() const;
406
407 // Borland C++ workaround
408 bool operator!() const;
409
410 // Comparison operators (compares wrapped attribute pointers)
411 bool operator==(const xml_attribute& r) const;
412 bool operator!=(const xml_attribute& r) const;
413 bool operator<(const xml_attribute& r) const;
414 bool operator>(const xml_attribute& r) const;
415 bool operator<=(const xml_attribute& r) const;
416 bool operator>=(const xml_attribute& r) const;
417
418 // Check if attribute is empty (null)
419 bool empty() const;
420
421 // Get attribute name/value, or "" if attribute is empty
422 const char_t* name() const;
423 const char_t* value() const;
424
425 // Get attribute value, or the default value if attribute is empty
426 const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
427
428 // Get attribute value as a number, or the default value if conversion did not succeed or attribute is empty
429 int as_int(int def = 0) const;
430 unsigned int as_uint(unsigned int def = 0) const;
431 double as_double(double def = 0) const;
432 float as_float(float def = 0) const;
433
434 #ifdef PUGIXML_HAS_LONG_LONG
435 long long as_llong(long long def = 0) const;
436 unsigned long long as_ullong(unsigned long long def = 0) const;
437 #endif
438
439 // Get attribute value as bool (returns true if first character is in '1tTyY' set), or the default value if attribute is empty
440 bool as_bool(bool def = false) const;
441
442 // Set attribute name/value (returns false if attribute is empty or there is not enough memory)
443 bool set_name(const char_t* rhs);
444 bool set_name(const char_t* rhs, size_t size);
445 #ifdef PUGIXML_HAS_STRING_VIEW
446 bool set_name(string_view_t rhs);
447 #endif
448 bool set_value(const char_t* rhs);
449 bool set_value(const char_t* rhs, size_t size);
450 #ifdef PUGIXML_HAS_STRING_VIEW
451 bool set_value(string_view_t rhs);
452 #endif
453
454 // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
455 bool set_value(int rhs);
456 bool set_value(unsigned int rhs);
457 bool set_value(long rhs);
458 bool set_value(unsigned long rhs);
459 bool set_value(double rhs);
460 bool set_value(double rhs, int precision);
461 bool set_value(float rhs);
462 bool set_value(float rhs, int precision);
463 bool set_value(bool rhs);
464
465 #ifdef PUGIXML_HAS_LONG_LONG
466 bool set_value(long long rhs);
467 bool set_value(unsigned long long rhs);
468 #endif
469
470 // Set attribute value (equivalent to set_value without error checking)
473 xml_attribute& operator=(unsigned int rhs);
475 xml_attribute& operator=(unsigned long rhs);
479
480 #ifdef PUGIXML_HAS_STRING_VIEW
481 xml_attribute& operator=(string_view_t rhs);
482 #endif
483
484 #ifdef PUGIXML_HAS_LONG_LONG
485 xml_attribute& operator=(long long rhs);
486 xml_attribute& operator=(unsigned long long rhs);
487 #endif
488
489 // Get next/previous attribute in the attribute list of the parent node
492
493 // Get hash value (unique for handles to the same object)
494 size_t hash_value() const;
495
496 // Get internal pointer
497 xml_attribute_struct* internal_object() const;
498 };
499
500#ifdef __BORLANDC__
501 // Borland C++ workaround
502 bool PUGIXML_FUNCTION operator&&(const xml_attribute& lhs, bool rhs);
503 bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs);
504#endif
505
506 // A light-weight handle for manipulating nodes in DOM tree
508 {
510 friend class xml_node_iterator;
512
513 protected:
514 xml_node_struct* _root;
515
516 typedef void (*unspecified_bool_type)(xml_node***);
517
518 public:
519 // Default constructor. Constructs an empty node.
521
522 // Constructs node from internal pointer
523 explicit xml_node(xml_node_struct* p);
524
525 // Safe bool conversion operator
526 operator unspecified_bool_type() const;
527
528 // Borland C++ workaround
529 bool operator!() const;
530
531 // Comparison operators (compares wrapped node pointers)
532 bool operator==(const xml_node& r) const;
533 bool operator!=(const xml_node& r) const;
534 bool operator<(const xml_node& r) const;
535 bool operator>(const xml_node& r) const;
536 bool operator<=(const xml_node& r) const;
537 bool operator>=(const xml_node& r) const;
538
539 // Check if node is empty (null)
540 bool empty() const;
541
542 // Get node type
544
545 // Get node name, or "" if node is empty or it has no name
546 const char_t* name() const;
547
548 // Get node value, or "" if node is empty or it has no value
549 // Note: For <node>text</node> node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes.
550 const char_t* value() const;
551
552 // Get attribute list
555
556 // Get children list
559
560 // Get next/previous sibling in the children list of the parent node
563
564 // Get parent node
566
567 // Get root of DOM tree this node belongs to
568 xml_node root() const;
569
570 // Get text object for the current node
571 xml_text text() const;
572
573 // Get child, attribute or next/previous sibling with the specified name
574 xml_node child(const char_t* name) const;
575 xml_attribute attribute(const char_t* name) const;
576 xml_node next_sibling(const char_t* name) const;
577 xml_node previous_sibling(const char_t* name) const;
578 #ifdef PUGIXML_HAS_STRING_VIEW
579 xml_node child(string_view_t name) const;
580 xml_attribute attribute(string_view_t name) const;
581 xml_node next_sibling(string_view_t name) const;
582 xml_node previous_sibling(string_view_t name) const;
583 #endif
584
585 // Get attribute, starting the search from a hint (and updating hint so that searching for a sequence of attributes is fast)
586 xml_attribute attribute(const char_t* name, xml_attribute& hint) const;
587 #ifdef PUGIXML_HAS_STRING_VIEW
588 xml_attribute attribute(string_view_t name, xml_attribute& hint) const;
589 #endif
590
591 // Get child value of current node; that is, value of the first child node of type PCDATA/CDATA
592 const char_t* child_value() const;
593
594 // Get child value of child with specified name. Equivalent to child(name).child_value().
595 const char_t* child_value(const char_t* name) const;
596
597 // Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value)
598 bool set_name(const char_t* rhs);
599 bool set_name(const char_t* rhs, size_t size);
600 #ifdef PUGIXML_HAS_STRING_VIEW
601 bool set_name(string_view_t rhs);
602 #endif
603 bool set_value(const char_t* rhs);
604 bool set_value(const char_t* rhs, size_t size);
605 #ifdef PUGIXML_HAS_STRING_VIEW
606 bool set_value(string_view_t rhs);
607 #endif
608
609 // Add attribute with specified name. Returns added attribute, or empty attribute on errors.
614 #ifdef PUGIXML_HAS_STRING_VIEW
615 xml_attribute append_attribute(string_view_t name);
616 xml_attribute prepend_attribute(string_view_t name);
617 xml_attribute insert_attribute_after(string_view_t name, const xml_attribute& attr);
618 xml_attribute insert_attribute_before(string_view_t name, const xml_attribute& attr);
619 #endif
620
621 // Add a copy of the specified attribute. Returns added attribute, or empty attribute on errors.
626
627 // Add child node with specified type. Returns added node, or empty node on errors.
628 xml_node append_child(xml_node_type type = node_element);
632
633 // Add child element with specified name. Returns added node, or empty node on errors.
636 xml_node insert_child_after(const char_t* name, const xml_node& node);
637 xml_node insert_child_before(const char_t* name, const xml_node& node);
638 #ifdef PUGIXML_HAS_STRING_VIEW
639 xml_node append_child(string_view_t name);
640 xml_node prepend_child(string_view_t name);
641 xml_node insert_child_after(string_view_t, const xml_node& node);
642 xml_node insert_child_before(string_view_t name, const xml_node& node);
643 #endif
644
645 // Add a copy of the specified node as a child. Returns added node, or empty node on errors.
648 xml_node insert_copy_after(const xml_node& proto, const xml_node& node);
649 xml_node insert_copy_before(const xml_node& proto, const xml_node& node);
650
651 // Move the specified node to become a child of this node. Returns moved node, or empty node on errors.
654 xml_node insert_move_after(const xml_node& moved, const xml_node& node);
655 xml_node insert_move_before(const xml_node& moved, const xml_node& node);
656
657 // Remove specified attribute
659 bool remove_attribute(const char_t* name);
660 #ifdef PUGIXML_HAS_STRING_VIEW
661 bool remove_attribute(string_view_t name);
662 #endif
663
664 // Remove all attributes
666
667 // Remove specified child
668 bool remove_child(const xml_node& n);
669 bool remove_child(const char_t* name);
670 #ifdef PUGIXML_HAS_STRING_VIEW
671 bool remove_child(string_view_t name);
672 #endif
673
674 // Remove all children
676
677 // Parses buffer as an XML document fragment and appends all nodes as children of the current node.
678 // Copies/converts the buffer, so it may be deleted or changed after the function returns.
679 // Note: append_buffer allocates memory that has the lifetime of the owning document; removing the appended nodes does not immediately reclaim that memory.
680 xml_parse_result append_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
681
682 // Find attribute using predicate. Returns first attribute for which predicate returned true.
683 template <typename Predicate> xml_attribute find_attribute(Predicate pred) const
684 {
685 if (!_root) return xml_attribute();
686
687 for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())
688 if (pred(attrib))
689 return attrib;
690
691 return xml_attribute();
692 }
693
694 // Find child node using predicate. Returns first child for which predicate returned true.
695 template <typename Predicate> xml_node find_child(Predicate pred) const
696 {
697 if (!_root) return xml_node();
698
699 for (xml_node node = first_child(); node; node = node.next_sibling())
700 if (pred(node))
701 return node;
702
703 return xml_node();
704 }
705
706 // Find node from subtree using predicate. Returns first node from subtree (depth-first), for which predicate returned true.
707 template <typename Predicate> xml_node find_node(Predicate pred) const
708 {
709 if (!_root) return xml_node();
710
711 xml_node cur = first_child();
712
713 while (cur._root && cur._root != _root)
714 {
715 if (pred(cur)) return cur;
716
717 if (cur.first_child()) cur = cur.first_child();
718 else if (cur.next_sibling()) cur = cur.next_sibling();
719 else
720 {
721 while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();
722
723 if (cur._root != _root) cur = cur.next_sibling();
724 }
725 }
726
727 return xml_node();
728 }
729
730 // Find child node by attribute name/value
731 xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
732 xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
733
734 #ifndef PUGIXML_NO_STL
735 // Get the absolute node path from root as a text string.
736 string_t path(char_t delimiter = '/') const;
737 #endif
738
739 // Search for a node by path consisting of node names and . or .. elements.
740 xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const;
741
742 // Recursively traverse subtree with xml_tree_walker
744
745 #ifndef PUGIXML_NO_XPATH
746 // Select single node by evaluating XPath query. Returns first node from the resulting node set.
748 xpath_node select_node(const xpath_query& query) const;
749
750 // Select node set by evaluating XPath query
753
754 // (deprecated: use select_node instead) Select single node by evaluating XPath query.
757
758 #endif
759
760 // Print subtree using a writer object
761 void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
762
763 #ifndef PUGIXML_NO_STL
764 // Print subtree to stream
765 void print(std::basic_ostream<char>& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
766 void print(std::basic_ostream<wchar_t>& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, unsigned int depth = 0) const;
767 #endif
768
769 // Child nodes iterators
771
773 iterator end() const;
774
775 // Attribute iterators
777
780
781 // Range-based for support
784
785 // Range-based for support for all children with the specified name
786 // Note: name pointer must have a longer lifetime than the returned object; be careful with passing temporaries!
788
789 // Get node offset in parsed file/string (in char_t units) for debugging purposes
790 ptrdiff_t offset_debug() const;
791
792 // Get hash value (unique for handles to the same object)
793 size_t hash_value() const;
794
795 // Get internal pointer
796 xml_node_struct* internal_object() const;
797 };
798
799#ifdef __BORLANDC__
800 // Borland C++ workaround
801 bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs);
802 bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs);
803#endif
804
805 // A helper for working with text inside PCDATA nodes
807 {
808 friend class xml_node;
809
810 xml_node_struct* _root;
811
812 typedef void (*unspecified_bool_type)(xml_text***);
813
814 explicit xml_text(xml_node_struct* root);
815
816 xml_node_struct* _data_new();
817 xml_node_struct* _data() const;
818
819 public:
820 // Default constructor. Constructs an empty object.
822
823 // Safe bool conversion operator
824 operator unspecified_bool_type() const;
825
826 // Borland C++ workaround
827 bool operator!() const;
828
829 // Check if text object is empty (null)
830 bool empty() const;
831
832 // Get text, or "" if object is empty
833 const char_t* get() const;
834
835 // Get text, or the default value if object is empty
836 const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
837
838 // Get text as a number, or the default value if conversion did not succeed or object is empty
839 int as_int(int def = 0) const;
840 unsigned int as_uint(unsigned int def = 0) const;
841 double as_double(double def = 0) const;
842 float as_float(float def = 0) const;
843
844 #ifdef PUGIXML_HAS_LONG_LONG
845 long long as_llong(long long def = 0) const;
846 unsigned long long as_ullong(unsigned long long def = 0) const;
847 #endif
848
849 // Get text as bool (returns true if first character is in '1tTyY' set), or the default value if object is empty
850 bool as_bool(bool def = false) const;
851
852 // Set text (returns false if object is empty or there is not enough memory)
853 bool set(const char_t* rhs);
854 bool set(const char_t* rhs, size_t size);
855 #ifdef PUGIXML_HAS_STRING_VIEW
856 bool set(string_view_t rhs);
857 #endif
858
859 // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
860 bool set(int rhs);
861 bool set(unsigned int rhs);
862 bool set(long rhs);
863 bool set(unsigned long rhs);
864 bool set(double rhs);
865 bool set(double rhs, int precision);
866 bool set(float rhs);
867 bool set(float rhs, int precision);
868 bool set(bool rhs);
869
870 #ifdef PUGIXML_HAS_LONG_LONG
871 bool set(long long rhs);
872 bool set(unsigned long long rhs);
873 #endif
874
875 // Set text (equivalent to set without error checking)
878 xml_text& operator=(unsigned int rhs);
879 xml_text& operator=(long rhs);
880 xml_text& operator=(unsigned long rhs);
881 xml_text& operator=(double rhs);
882 xml_text& operator=(float rhs);
883 xml_text& operator=(bool rhs);
884
885 #ifdef PUGIXML_HAS_STRING_VIEW
886 xml_text& operator=(string_view_t rhs);
887 #endif
888
889 #ifdef PUGIXML_HAS_LONG_LONG
890 xml_text& operator=(long long rhs);
891 xml_text& operator=(unsigned long long rhs);
892 #endif
893
894 // Get the data node (node_pcdata or node_cdata) for this object
895 xml_node data() const;
896 };
897
898#ifdef __BORLANDC__
899 // Borland C++ workaround
900 bool PUGIXML_FUNCTION operator&&(const xml_text& lhs, bool rhs);
901 bool PUGIXML_FUNCTION operator||(const xml_text& lhs, bool rhs);
902#endif
903
904 // Child node iterator (a bidirectional iterator over a collection of xml_node)
906 {
907 friend class xml_node;
908
909 private:
912
913 xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent);
914
915 public:
916 // Iterator traits
917 typedef ptrdiff_t difference_type;
921
922 #ifndef PUGIXML_NO_STL
923 typedef std::bidirectional_iterator_tag iterator_category;
924 #endif
925
926 // Default constructor
928
929 // Construct an iterator which points to the specified node
931
932 // Iterator operators
933 bool operator==(const xml_node_iterator& rhs) const;
934 bool operator!=(const xml_node_iterator& rhs) const;
935
938
941
944 };
945
946 // Attribute iterator (a bidirectional iterator over a collection of xml_attribute)
948 {
949 friend class xml_node;
950
951 private:
954
955 xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent);
956
957 public:
958 // Iterator traits
959 typedef ptrdiff_t difference_type;
963
964 #ifndef PUGIXML_NO_STL
965 typedef std::bidirectional_iterator_tag iterator_category;
966 #endif
967
968 // Default constructor
970
971 // Construct an iterator which points to the specified attribute
972 xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent);
973
974 // Iterator operators
975 bool operator==(const xml_attribute_iterator& rhs) const;
976 bool operator!=(const xml_attribute_iterator& rhs) const;
977
980
983
986 };
987
988 // Named node range helper
990 {
991 friend class xml_node;
992
993 public:
994 // Iterator traits
995 typedef ptrdiff_t difference_type;
999
1000 #ifndef PUGIXML_NO_STL
1001 typedef std::bidirectional_iterator_tag iterator_category;
1002 #endif
1003
1004 // Default constructor
1006
1007 // Construct an iterator which points to the specified node
1008 // Note: name pointer is stored in the iterator and must have a longer lifetime than iterator itself
1009 xml_named_node_iterator(const xml_node& node, const char_t* name);
1010
1011 // Iterator operators
1012 bool operator==(const xml_named_node_iterator& rhs) const;
1013 bool operator!=(const xml_named_node_iterator& rhs) const;
1014
1017
1020
1023
1024 private:
1028
1029 xml_named_node_iterator(xml_node_struct* ref, xml_node_struct* parent, const char_t* name);
1030 };
1031
1032 // Abstract tree walker class (see xml_node::traverse)
1034 {
1035 friend class xml_node;
1036
1037 private:
1039
1040 protected:
1041 // Get current traversal depth
1042 int depth() const;
1043
1044 public:
1047
1048 // Callback that is called when traversal begins
1049 virtual bool begin(xml_node& node);
1050
1051 // Callback that is called for each node traversed
1052 virtual bool for_each(xml_node& node) = 0;
1053
1054 // Callback that is called when traversal ends
1055 virtual bool end(xml_node& node);
1056 };
1057
1058 // Parsing status, returned as part of xml_parse_result object
1060 {
1061 status_ok = 0, // No error
1062
1063 status_file_not_found, // File was not found during load_file()
1064 status_io_error, // Error reading from file/stream
1065 status_out_of_memory, // Could not allocate memory
1066 status_internal_error, // Internal error occurred
1067
1068 status_unrecognized_tag, // Parser could not determine tag type
1069
1070 status_bad_pi, // Parsing error occurred while parsing document declaration/processing instruction
1071 status_bad_comment, // Parsing error occurred while parsing comment
1072 status_bad_cdata, // Parsing error occurred while parsing CDATA section
1073 status_bad_doctype, // Parsing error occurred while parsing document type declaration
1074 status_bad_pcdata, // Parsing error occurred while parsing PCDATA section
1075 status_bad_start_element, // Parsing error occurred while parsing start element tag
1076 status_bad_attribute, // Parsing error occurred while parsing element attribute
1077 status_bad_end_element, // Parsing error occurred while parsing end element tag
1078 status_end_element_mismatch,// There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or there was an excessive closing tag)
1079
1080 status_append_invalid_root, // Unable to append nodes since root type is not node_element or node_document (exclusive to xml_node::append_buffer)
1081
1082 status_no_document_element // Parsing resulted in a document without element nodes
1084
1085 // Parsing result
1087 {
1088 // Parsing status (see xml_parse_status)
1090
1091 // Last parsed offset (in char_t units from start of input data)
1092 ptrdiff_t offset;
1093
1094 // Source document encoding
1096
1097 // Default constructor, initializes object to failed state
1099
1100 // Cast to bool operator
1101 operator bool() const;
1102
1103 // Get error description
1104 const char* description() const;
1105 };
1106
1107 // Document class (DOM tree root)
1109 {
1110 private:
1112
1113 char _memory[192];
1114
1115 // Non-copyable semantics
1118
1119 void _create();
1120 void _destroy();
1122
1123 public:
1124 // Default constructor, makes empty document
1126
1127 // Destructor, invalidates all node/attribute handles to this document
1129
1130 #ifdef PUGIXML_HAS_MOVE
1131 // Move semantics support
1134 #endif
1135
1136 // Removes all nodes, leaving the empty document
1137 void reset();
1138
1139 // Removes all nodes, then copies the entire contents of the specified document
1140 void reset(const xml_document& proto);
1141
1142 #ifndef PUGIXML_NO_STL
1143 // Load document from stream.
1144 xml_parse_result load(std::basic_istream<char>& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1145 xml_parse_result load(std::basic_istream<wchar_t>& stream, unsigned int options = parse_default);
1146 #endif
1147
1148 // (deprecated: use load_string instead) Load document from zero-terminated string. No encoding conversions are applied.
1149 PUGIXML_DEPRECATED xml_parse_result load(const char_t* contents, unsigned int options = parse_default);
1150
1151 // Load document from zero-terminated string. No encoding conversions are applied.
1152 xml_parse_result load_string(const char_t* contents, unsigned int options = parse_default);
1153
1154 // Load document from file
1155 xml_parse_result load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1156 xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1157
1158 // Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns.
1159 xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1160
1161 // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
1162 // You should ensure that buffer data will persist throughout the document's lifetime, and free the buffer memory manually once document is destroyed.
1163 xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1164
1165 // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
1166 // You should allocate the buffer with pugixml allocation function; document will free the buffer when it is no longer needed (you can't use it anymore).
1167 xml_parse_result load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1168
1169 // Save XML document to writer (semantics is slightly different from xml_node::print, see documentation for details).
1170 void save(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1171
1172 #ifndef PUGIXML_NO_STL
1173 // Save XML document to stream (semantics is slightly different from xml_node::print, see documentation for details).
1174 void save(std::basic_ostream<char>& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1175 void save(std::basic_ostream<wchar_t>& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const;
1176 #endif
1177
1178 // Save XML to file
1179 bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1180 bool save_file(const wchar_t* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1181
1182 // Get document element
1184 };
1185
1186#ifndef PUGIXML_NO_XPATH
1187 // XPath query return type
1189 {
1190 xpath_type_none, // Unknown type (query failed to compile)
1191 xpath_type_node_set, // Node set (xpath_node_set)
1194 xpath_type_boolean // Boolean
1196
1197 // XPath parsing result
1199 {
1200 // Error message (0 if no error)
1201 const char* error;
1202
1203 // Last parsed offset (in char_t units from string start)
1204 ptrdiff_t offset;
1205
1206 // Default constructor, initializes object to failed state
1208
1209 // Cast to bool operator
1210 operator bool() const;
1211
1212 // Get error description
1213 const char* description() const;
1214 };
1215
1216 // A single XPath variable
1218 {
1220
1221 protected:
1224
1226
1227 // Non-copyable semantics
1230
1231 public:
1232 // Get variable name
1233 const char_t* name() const;
1234
1235 // Get variable type
1237
1238 // Get variable value; no type conversion is performed, default value (false, NaN, empty string, empty node set) is returned on type mismatch error
1239 bool get_boolean() const;
1240 double get_number() const;
1241 const char_t* get_string() const;
1243
1244 // Set variable value; no type conversion is performed, false is returned on type mismatch error
1245 bool set(bool value);
1246 bool set(double value);
1247 bool set(const char_t* value);
1248 bool set(const xpath_node_set& value);
1249 };
1250
1251 // A set of XPath variables
1253 {
1254 private:
1255 xpath_variable* _data[64];
1256
1257 void _assign(const xpath_variable_set& rhs);
1259
1260 xpath_variable* _find(const char_t* name) const;
1261
1262 static bool _clone(xpath_variable* var, xpath_variable** out_result);
1263 static void _destroy(xpath_variable* var);
1264
1265 public:
1266 // Default constructor/destructor
1269
1270 // Copy constructor/assignment operator
1273
1274 #ifdef PUGIXML_HAS_MOVE
1275 // Move semantics support
1278 #endif
1279
1280 // Add a new variable or get the existing one, if the types match
1282
1283 // Set value of an existing variable; no type conversion is performed, false is returned if there is no such variable or if types mismatch
1284 bool set(const char_t* name, bool value);
1285 bool set(const char_t* name, double value);
1286 bool set(const char_t* name, const char_t* value);
1287 bool set(const char_t* name, const xpath_node_set& value);
1288
1289 // Get existing variable by name
1291 const xpath_variable* get(const char_t* name) const;
1292 };
1293
1294 // A compiled XPath query object
1296 {
1297 private:
1298 void* _impl;
1300
1301 typedef void (*unspecified_bool_type)(xpath_query***);
1302
1303 // Non-copyable semantics
1306
1307 public:
1308 // Construct a compiled object from XPath expression.
1309 // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on compilation errors.
1310 explicit xpath_query(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL);
1311
1312 // Constructor
1314
1315 // Destructor
1317
1318 #ifdef PUGIXML_HAS_MOVE
1319 // Move semantics support
1321 xpath_query& operator=(xpath_query&& rhs) PUGIXML_NOEXCEPT;
1322 #endif
1323
1324 // Get query expression return type
1326
1327 // Evaluate expression as boolean value in the specified context; performs type conversion if necessary.
1328 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1329 bool evaluate_boolean(const xpath_node& n) const;
1330
1331 // Evaluate expression as double value in the specified context; performs type conversion if necessary.
1332 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1333 double evaluate_number(const xpath_node& n) const;
1334
1335 #ifndef PUGIXML_NO_STL
1336 // Evaluate expression as string value in the specified context; performs type conversion if necessary.
1337 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1339 #endif
1340
1341 // Evaluate expression as string value in the specified context; performs type conversion if necessary.
1342 // At most capacity characters are written to the destination buffer, full result size is returned (includes terminating zero).
1343 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1344 // If PUGIXML_NO_EXCEPTIONS is defined, returns empty set instead.
1345 size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const;
1346
1347 // Evaluate expression as node set in the specified context.
1348 // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on type mismatch and std::bad_alloc on out of memory errors.
1349 // If PUGIXML_NO_EXCEPTIONS is defined, returns empty node set instead.
1351
1352 // Evaluate expression as node set in the specified context.
1353 // Return first node in document order, or empty node if node set is empty.
1354 // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on type mismatch and std::bad_alloc on out of memory errors.
1355 // If PUGIXML_NO_EXCEPTIONS is defined, returns empty node instead.
1357
1358 // Get parsing result (used to get compilation errors in PUGIXML_NO_EXCEPTIONS mode)
1360
1361 // Safe bool conversion operator
1362 operator unspecified_bool_type() const;
1363
1364 // Borland C++ workaround
1365 bool operator!() const;
1366 };
1367
1368 #ifndef PUGIXML_NO_EXCEPTIONS
1369 #if defined(_MSC_VER)
1370 // C4275 can be ignored in Visual C++ if you are deriving
1371 // from a type in the Standard C++ Library
1372 #pragma warning(push)
1373 #pragma warning(disable: 4275)
1374 #endif
1375 // XPath exception class
1376 class PUGIXML_CLASS xpath_exception: public std::exception
1377 {
1378 private:
1379 xpath_parse_result _result;
1380
1381 public:
1382 // Construct exception from parse result
1383 explicit xpath_exception(const xpath_parse_result& result);
1384
1385 // Get error message
1386 virtual const char* what() const PUGIXML_NOEXCEPT PUGIXML_OVERRIDE;
1387
1388 // Get parse result
1389 const xpath_parse_result& result() const;
1390 };
1391 #if defined(_MSC_VER)
1392 #pragma warning(pop)
1393 #endif
1394 #endif
1395
1396 // XPath node class (either xml_node or xml_attribute)
1398 {
1399 private:
1402
1403 typedef void (*unspecified_bool_type)(xpath_node***);
1404
1405 public:
1406 // Default constructor; constructs empty XPath node
1408
1409 // Construct XPath node from XML node/attribute
1410 xpath_node(const xml_node& node);
1411 xpath_node(const xml_attribute& attribute, const xml_node& parent);
1412
1413 // Get node/attribute, if any
1416
1417 // Get parent of contained node/attribute
1419
1420 // Safe bool conversion operator
1421 operator unspecified_bool_type() const;
1422
1423 // Borland C++ workaround
1424 bool operator!() const;
1425
1426 // Comparison operators
1427 bool operator==(const xpath_node& n) const;
1428 bool operator!=(const xpath_node& n) const;
1429 };
1430
1431#ifdef __BORLANDC__
1432 // Borland C++ workaround
1433 bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs);
1434 bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs);
1435#endif
1436
1437 // A fixed-size collection of XPath nodes
1439 {
1440 public:
1441 // Collection type
1443 {
1444 type_unsorted, // Not ordered
1445 type_sorted, // Sorted by document order (ascending)
1446 type_sorted_reverse // Sorted by document order (descending)
1448
1449 // Constant iterator type
1451
1452 // We define non-constant iterator to be the same as constant iterator so that various generic algorithms (i.e. boost foreach) work
1453 typedef const xpath_node* iterator;
1454
1455 // Default constructor. Constructs empty set.
1457
1458 // Constructs a set from iterator range; data is not checked for duplicates and is not sorted according to provided type, so be careful
1459 xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted);
1460
1461 // Destructor
1463
1464 // Copy constructor/assignment operator
1467
1468 #ifdef PUGIXML_HAS_MOVE
1469 // Move semantics support
1472 #endif
1473
1474 // Get collection type
1475 type_t type() const;
1476
1477 // Get collection size
1478 size_t size() const;
1479
1480 // Indexing operator
1481 const xpath_node& operator[](size_t index) const;
1482
1483 // Collection iterators
1486
1487 // Sort the collection in ascending/descending order by document order
1488 void sort(bool reverse = false);
1489
1490 // Get first node in the collection by document order
1492
1493 // Check if collection is empty
1494 bool empty() const;
1495
1496 private:
1498
1499 xpath_node _storage[1];
1500
1503
1506 };
1507#endif
1508
1509#ifndef PUGIXML_NO_STL
1510 // Convert wide string to UTF8
1511 std::basic_string<char> PUGIXML_FUNCTION as_utf8(const wchar_t* str);
1512 std::basic_string<char> PUGIXML_FUNCTION as_utf8(const std::basic_string<wchar_t>& str);
1513
1514 // Convert UTF8 to wide string
1515 std::basic_string<wchar_t> PUGIXML_FUNCTION as_wide(const char* str);
1516 std::basic_string<wchar_t> PUGIXML_FUNCTION as_wide(const std::basic_string<char>& str);
1517#endif
1518
1519 // Memory allocation function interface; returns pointer to allocated memory or NULL on failure
1520 typedef void* (*allocation_function)(size_t size);
1521
1522 // Memory deallocation function interface
1523 typedef void (*deallocation_function)(void* ptr);
1524
1525 // Override default memory management functions. All subsequent allocations/deallocations will be performed via supplied functions.
1526 void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate);
1527
1528 // Get current memory management functions
1531}
1532
1533#if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
1534namespace std
1535{
1536 // Workarounds for (non-standard) iterator category detection for older versions (MSVC7/IC8 and earlier)
1537 std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_node_iterator&);
1538 std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_attribute_iterator&);
1539 std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_named_node_iterator&);
1540}
1541#endif
1542
1543#if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
1544namespace std
1545{
1546 // Workarounds for (non-standard) iterator category detection
1547 std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_node_iterator&);
1548 std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_attribute_iterator&);
1549 std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_named_node_iterator&);
1550}
1551#endif
1552
1553#endif
1554
1555// Make sure implementation is included in header-only mode
1556// Use macro expansion in #include to work around QMake (QTBUG-11923)
1557#if defined(PUGIXML_HEADER_ONLY) && !defined(PUGIXML_SOURCE)
1558# define PUGIXML_SOURCE "pugixml.cpp"
1559# include PUGIXML_SOURCE
1560#endif
1561
xml_attribute * operator->() const
xml_attribute_iterator & operator++()
xml_attribute_iterator operator--(int)
xml_attribute_iterator & operator--()
xml_attribute_iterator operator++(int)
xml_attribute * pointer
Definition pugixml.h:961
xml_attribute_iterator(xml_attribute_struct *ref, xml_node_struct *parent)
std::bidirectional_iterator_tag iterator_category
Definition pugixml.h:965
xml_attribute_iterator(const xml_attribute &attr, const xml_node &parent)
bool operator==(const xml_attribute_iterator &rhs) const
xml_attribute & reference
Definition pugixml.h:962
bool operator!=(const xml_attribute_iterator &rhs) const
xml_attribute & operator*() const
bool set_value(float rhs, int precision)
bool operator>(const xml_attribute &r) const
xml_attribute & operator=(unsigned long rhs)
bool set_value(const char_t *rhs, size_t size)
xml_attribute & operator=(long rhs)
bool set_value(unsigned long long rhs)
unsigned long long as_ullong(unsigned long long def=0) const
bool operator<=(const xml_attribute &r) const
xml_attribute & operator=(unsigned int rhs)
xml_attribute & operator=(const char_t *rhs)
xml_attribute next_attribute() const
xml_attribute & operator=(long long rhs)
bool set_value(double rhs, int precision)
size_t hash_value() const
xml_attribute_struct * internal_object() const
xml_attribute(xml_attribute_struct *attr)
bool operator!() const
bool as_bool(bool def=false) const
const char_t * value() const
bool set_name(const char_t *rhs, size_t size)
float as_float(float def=0) const
xml_attribute & operator=(unsigned long long rhs)
const char_t * name() const
bool set_value(const char_t *rhs)
bool set_value(double rhs)
bool set_value(long long rhs)
bool empty() const
bool operator>=(const xml_attribute &r) const
bool operator==(const xml_attribute &r) const
const char_t * as_string(const char_t *def=PUGIXML_TEXT("")) const
double as_double(double def=0) const
bool operator<(const xml_attribute &r) const
unsigned int as_uint(unsigned int def=0) const
xml_attribute_struct * _attr
Definition pugixml.h:393
bool set_value(int rhs)
bool set_value(long rhs)
xml_attribute previous_attribute() const
bool set_value(unsigned int rhs)
bool operator!=(const xml_attribute &r) const
long long as_llong(long long def=0) const
xml_attribute & operator=(float rhs)
xml_attribute & operator=(double rhs)
bool set_name(const char_t *rhs)
bool set_value(float rhs)
bool set_value(unsigned long rhs)
xml_attribute & operator=(bool rhs)
xml_attribute & operator=(int rhs)
int as_int(int def=0) const
bool set_value(bool rhs)
xml_parse_result load_buffer_inplace_own(void *contents, size_t size, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
xml_parse_result load(std::basic_istream< wchar_t > &stream, unsigned int options=parse_default)
xml_parse_result load_file(const char *path, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
bool save_file(const wchar_t *path, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, xml_encoding encoding=encoding_auto) const
xml_document(const xml_document &)
void save(xml_writer &writer, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, xml_encoding encoding=encoding_auto) const
xml_parse_result load_string(const char_t *contents, unsigned int options=parse_default)
xml_parse_result load_file(const wchar_t *path, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
xml_parse_result load(std::basic_istream< char > &stream, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
void save(std::basic_ostream< wchar_t > &stream, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default) const
xml_node document_element() const
xml_document & operator=(const xml_document &)
void reset(const xml_document &proto)
xml_parse_result load_buffer_inplace(void *contents, size_t size, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
PUGIXML_DEPRECATED xml_parse_result load(const char_t *contents, unsigned int options=parse_default)
bool save_file(const char *path, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, xml_encoding encoding=encoding_auto) const
void save(std::basic_ostream< char > &stream, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, xml_encoding encoding=encoding_auto) const
void _move(xml_document &rhs) PUGIXML_NOEXCEPT_IF_NOT_COMPACT
xml_parse_result load_buffer(const void *contents, size_t size, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
xml_named_node_iterator & operator++()
xml_named_node_iterator(xml_node_struct *ref, xml_node_struct *parent, const char_t *name)
bool operator!=(const xml_named_node_iterator &rhs) const
xml_named_node_iterator(const xml_node &node, const char_t *name)
xml_named_node_iterator & operator--()
xml_named_node_iterator operator--(int)
xml_node & operator*() const
xml_named_node_iterator operator++(int)
std::bidirectional_iterator_tag iterator_category
Definition pugixml.h:1001
xml_node * operator->() const
bool operator==(const xml_named_node_iterator &rhs) const
bool operator==(const xml_node_iterator &rhs) const
xml_node_iterator & operator++()
xml_node_iterator(xml_node_struct *ref, xml_node_struct *parent)
xml_node_iterator(const xml_node &node)
xml_node_iterator operator--(int)
bool operator!=(const xml_node_iterator &rhs) const
xml_node_iterator & operator--()
std::bidirectional_iterator_tag iterator_category
Definition pugixml.h:923
xml_node_iterator operator++(int)
ptrdiff_t difference_type
Definition pugixml.h:917
xml_node * operator->() const
xml_node & operator*() const
xml_node insert_copy_after(const xml_node &proto, const xml_node &node)
bool set_value(const char_t *rhs, size_t size)
bool remove_child(const xml_node &n)
xml_node insert_move_before(const xml_node &moved, const xml_node &node)
PUGIXML_DEPRECATED xpath_node select_single_node(const xpath_query &query) const
iterator begin() const
xml_node insert_child_before(const char_t *name, const xml_node &node)
xml_node prepend_copy(const xml_node &proto)
const char_t * value() const
bool operator>=(const xml_node &r) const
bool operator<=(const xml_node &r) const
xml_node insert_move_after(const xml_node &moved, const xml_node &node)
PUGIXML_DEPRECATED xpath_node select_single_node(const char_t *query, xpath_variable_set *variables=PUGIXML_NULL) const
xml_node find_child_by_attribute(const char_t *attr_name, const char_t *attr_value) const
xpath_node_set select_nodes(const char_t *query, xpath_variable_set *variables=PUGIXML_NULL) const
xml_node prepend_move(const xml_node &moved)
xml_node next_sibling(const char_t *name) const
xml_attribute first_attribute() const
xml_attribute insert_copy_after(const xml_attribute &proto, const xml_attribute &attr)
bool operator!=(const xml_node &r) const
xml_attribute insert_attribute_after(const char_t *name, const xml_attribute &attr)
bool traverse(xml_tree_walker &walker)
xml_attribute find_attribute(Predicate pred) const
Definition pugixml.h:683
xml_node prepend_child(xml_node_type type=node_element)
xml_node_struct * _root
Definition pugixml.h:514
xml_attribute append_attribute(const char_t *name)
xpath_node select_node(const xpath_query &query) const
xml_node append_child(xml_node_type type=node_element)
xml_node first_element_by_path(const char_t *path, char_t delimiter='/') const
xml_node_struct * internal_object() const
xml_node append_copy(const xml_node &proto)
xml_object_range< xml_node_iterator > children() const
const char_t * name() const
xml_attribute insert_attribute_before(const char_t *name, const xml_attribute &attr)
xml_node(xml_node_struct *p)
xml_node find_child_by_attribute(const char_t *name, const char_t *attr_name, const char_t *attr_value) const
xml_object_range< xml_attribute_iterator > attributes() const
xml_node previous_sibling(const char_t *name) const
bool set_name(const char_t *rhs, size_t size)
bool set_name(const char_t *rhs)
xml_node root() const
xml_attribute prepend_attribute(const char_t *name)
ptrdiff_t offset_debug() const
bool remove_attributes()
xml_node first_child() const
xml_node append_child(const char_t *name)
xml_node previous_sibling() const
xml_attribute prepend_copy(const xml_attribute &proto)
xml_node append_move(const xml_node &moved)
xml_object_range< xml_named_node_iterator > children(const char_t *name) const
xml_node insert_copy_before(const xml_node &proto, const xml_node &node)
bool remove_child(const char_t *name)
xml_attribute attribute(const char_t *name) const
xml_node find_node(Predicate pred) const
Definition pugixml.h:707
void print(std::basic_ostream< wchar_t > &os, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, unsigned int depth=0) const
bool operator<(const xml_node &r) const
void print(std::basic_ostream< char > &os, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, xml_encoding encoding=encoding_auto, unsigned int depth=0) const
attribute_iterator attributes_begin() const
xml_attribute_iterator attribute_iterator
Definition pugixml.h:776
iterator end() const
bool operator==(const xml_node &r) const
xml_attribute last_attribute() const
xml_attribute insert_copy_before(const xml_attribute &proto, const xml_attribute &attr)
bool remove_attribute(const char_t *name)
xml_parse_result append_buffer(const void *contents, size_t size, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
xml_node insert_child_before(xml_node_type type, const xml_node &node)
bool remove_children()
xml_node parent() const
bool operator!() const
xml_node last_child() const
void print(xml_writer &writer, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, xml_encoding encoding=encoding_auto, unsigned int depth=0) const
const char_t * child_value() const
xml_attribute append_copy(const xml_attribute &proto)
size_t hash_value() const
xml_text text() const
xml_node prepend_child(const char_t *name)
xml_node_type type() const
xml_node find_child(Predicate pred) const
Definition pugixml.h:695
xml_attribute attribute(const char_t *name, xml_attribute &hint) const
xml_node insert_child_after(const char_t *name, const xml_node &node)
bool remove_attribute(const xml_attribute &a)
const char_t * child_value(const char_t *name) const
string_t path(char_t delimiter='/') const
bool empty() const
xpath_node select_node(const char_t *query, xpath_variable_set *variables=PUGIXML_NULL) const
xpath_node_set select_nodes(const xpath_query &query) const
bool operator>(const xml_node &r) const
xml_node_iterator iterator
Definition pugixml.h:770
xml_node next_sibling() const
attribute_iterator attributes_end() const
xml_node child(const char_t *name) const
xml_node insert_child_after(xml_node_type type, const xml_node &node)
bool set_value(const char_t *rhs)
bool empty() const
Definition pugixml.h:340
xml_object_range(It b, It e)
Definition pugixml.h:333
bool empty() const
const char_t * as_string(const char_t *def=PUGIXML_TEXT("")) const
xml_text(xml_node_struct *root)
double as_double(double def=0) const
float as_float(float def=0) const
int as_int(int def=0) const
xml_node_struct * _data() const
bool set(double rhs, int precision)
bool set(float rhs)
xml_text & operator=(double rhs)
xml_text & operator=(int rhs)
bool set(unsigned int rhs)
xml_node_struct * _root
Definition pugixml.h:810
bool set(long rhs)
xml_text & operator=(long long rhs)
xml_text & operator=(unsigned long long rhs)
xml_text & operator=(long rhs)
bool set(const char_t *rhs, size_t size)
bool set(double rhs)
xml_text & operator=(bool rhs)
bool as_bool(bool def=false) const
bool set(const char_t *rhs)
long long as_llong(long long def=0) const
bool set(long long rhs)
xml_node_struct * _data_new()
bool set(int rhs)
unsigned long long as_ullong(unsigned long long def=0) const
bool operator!() const
bool set(float rhs, int precision)
bool set(unsigned long long rhs)
bool set(unsigned long rhs)
bool set(bool rhs)
xml_text & operator=(float rhs)
unsigned int as_uint(unsigned int def=0) const
xml_node data() const
const char_t * get() const
xml_text & operator=(const char_t *rhs)
xml_text & operator=(unsigned long rhs)
xml_text & operator=(unsigned int rhs)
virtual bool for_each(xml_node &node)=0
virtual ~xml_tree_walker()
virtual bool end(xml_node &node)
virtual bool begin(xml_node &node)
virtual void write(const void *data, size_t size) PUGIXML_OVERRIDE
xml_writer_file(void *file)
std::basic_ostream< wchar_t > * wide_stream
Definition pugixml.h:382
xml_writer_stream(std::basic_ostream< wchar_t > &stream)
virtual void write(const void *data, size_t size) PUGIXML_OVERRIDE
std::basic_ostream< char > * narrow_stream
Definition pugixml.h:381
xml_writer_stream(std::basic_ostream< char > &stream)
virtual ~xml_writer()
virtual void write(const void *data, size_t size)=0
const_iterator begin() const
xpath_node_set(const_iterator begin, const_iterator end, type_t type=type_unsorted)
void sort(bool reverse=false)
xpath_node_set(const xpath_node_set &ns)
const xpath_node * const_iterator
Definition pugixml.h:1450
const_iterator end() const
xpath_node first() const
const xpath_node & operator[](size_t index) const
bool empty() const
void _assign(const_iterator begin, const_iterator end, type_t type)
const xpath_node * iterator
Definition pugixml.h:1453
xpath_node * _begin
Definition pugixml.h:1501
size_t size() const
xpath_node_set & operator=(const xpath_node_set &ns)
type_t type() const
xpath_node * _end
Definition pugixml.h:1502
void _move(xpath_node_set &rhs) PUGIXML_NOEXCEPT
xml_node parent() const
xml_attribute attribute() const
bool operator!=(const xpath_node &n) const
xml_node _node
Definition pugixml.h:1400
xml_node node() const
xpath_node(const xml_attribute &attribute, const xml_node &parent)
bool operator==(const xpath_node &n) const
bool operator!() const
xpath_node(const xml_node &node)
xml_attribute _attribute
Definition pugixml.h:1401
xpath_node_set evaluate_node_set(const xpath_node &n) const
string_t evaluate_string(const xpath_node &n) const
size_t evaluate_string(char_t *buffer, size_t capacity, const xpath_node &n) const
xpath_parse_result _result
Definition pugixml.h:1299
xpath_node evaluate_node(const xpath_node &n) const
xpath_query & operator=(const xpath_query &)
double evaluate_number(const xpath_node &n) const
const xpath_parse_result & result() const
xpath_query(const xpath_query &)
xpath_value_type return_type() const
xpath_query(const char_t *query, xpath_variable_set *variables=PUGIXML_NULL)
bool evaluate_boolean(const xpath_node &n) const
bool operator!() const
void _swap(xpath_variable_set &rhs)
const xpath_variable * get(const char_t *name) const
xpath_variable * _find(const char_t *name) const
xpath_variable_set & operator=(const xpath_variable_set &rhs)
bool set(const char_t *name, const xpath_node_set &value)
bool set(const char_t *name, bool value)
bool set(const char_t *name, const char_t *value)
bool set(const char_t *name, double value)
xpath_variable * get(const char_t *name)
static bool _clone(xpath_variable *var, xpath_variable **out_result)
void _assign(const xpath_variable_set &rhs)
static void _destroy(xpath_variable *var)
xpath_variable_set(const xpath_variable_set &rhs)
xpath_variable * add(const char_t *name, xpath_value_type type)
xpath_variable * _next
Definition pugixml.h:1223
bool set(const char_t *value)
xpath_variable(const xpath_variable &)
bool get_boolean() const
xpath_value_type type() const
xpath_variable(xpath_value_type type)
double get_number() const
const xpath_node_set & get_node_set() const
const char_t * get_string() const
const char_t * name() const
bool set(bool value)
xpath_variable & operator=(const xpath_variable &)
bool set(double value)
bool set(const xpath_node_set &value)
xpath_value_type _type
Definition pugixml.h:1222
const unsigned int format_no_empty_element_tags
Definition pugixml.h:288
xml_encoding
Definition pugixml.h:251
@ encoding_utf32
Definition pugixml.h:259
@ encoding_utf16_le
Definition pugixml.h:254
@ encoding_utf32_be
Definition pugixml.h:258
@ encoding_utf16_be
Definition pugixml.h:255
@ encoding_utf8
Definition pugixml.h:253
@ encoding_latin1
Definition pugixml.h:261
@ encoding_utf16
Definition pugixml.h:256
@ encoding_utf32_le
Definition pugixml.h:257
@ encoding_auto
Definition pugixml.h:252
@ encoding_wchar
Definition pugixml.h:260
deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function()
std::basic_string< wchar_t > PUGIXML_FUNCTION as_wide(const char *str)
allocation_function PUGIXML_FUNCTION get_memory_allocation_function()
const unsigned int format_no_declaration
Definition pugixml.h:276
xml_node_type
Definition pugixml.h:169
@ node_comment
Definition pugixml.h:175
@ node_pcdata
Definition pugixml.h:173
@ node_element
Definition pugixml.h:172
@ node_doctype
Definition pugixml.h:178
@ node_document
Definition pugixml.h:171
@ node_declaration
Definition pugixml.h:177
@ node_pi
Definition pugixml.h:176
@ node_null
Definition pugixml.h:170
@ node_cdata
Definition pugixml.h:174
const unsigned int parse_trim_pcdata
Definition pugixml.h:224
const unsigned int parse_wconv_attribute
Definition pugixml.h:207
const unsigned int format_skip_control_chars
Definition pugixml.h:291
const unsigned int format_raw
Definition pugixml.h:273
const unsigned int format_default
Definition pugixml.h:298
void(* deallocation_function)(void *ptr)
Definition pugixml.h:1523
const int default_double_precision
Definition pugixml.h:300
const unsigned int parse_cdata
Definition pugixml.h:194
void *(* allocation_function)(size_t size)
Definition pugixml.h:1520
const unsigned int parse_merge_pcdata
Definition pugixml.h:237
const unsigned int parse_fragment
Definition pugixml.h:228
const unsigned int parse_full
Definition pugixml.h:247
const unsigned int parse_embed_pcdata
Definition pugixml.h:233
const unsigned int parse_wnorm_attribute
Definition pugixml.h:210
const unsigned int format_indent_attributes
Definition pugixml.h:285
const unsigned int parse_pi
Definition pugixml.h:188
xml_parse_status
Definition pugixml.h:1060
@ status_append_invalid_root
Definition pugixml.h:1080
@ status_end_element_mismatch
Definition pugixml.h:1078
@ status_bad_end_element
Definition pugixml.h:1077
@ status_io_error
Definition pugixml.h:1064
@ status_bad_attribute
Definition pugixml.h:1076
@ status_file_not_found
Definition pugixml.h:1063
@ status_internal_error
Definition pugixml.h:1066
@ status_bad_start_element
Definition pugixml.h:1075
@ status_ok
Definition pugixml.h:1061
@ status_bad_comment
Definition pugixml.h:1071
@ status_bad_doctype
Definition pugixml.h:1073
@ status_out_of_memory
Definition pugixml.h:1065
@ status_unrecognized_tag
Definition pugixml.h:1068
@ status_bad_cdata
Definition pugixml.h:1072
@ status_bad_pcdata
Definition pugixml.h:1074
@ status_bad_pi
Definition pugixml.h:1070
@ status_no_document_element
Definition pugixml.h:1082
std::basic_string< char > PUGIXML_FUNCTION as_utf8(const wchar_t *str)
const unsigned int format_save_file_text
Definition pugixml.h:282
const unsigned int parse_escapes
Definition pugixml.h:201
const unsigned int format_write_bom
Definition pugixml.h:270
void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate)
const unsigned int format_attribute_single_quote
Definition pugixml.h:294
const unsigned int format_indent
Definition pugixml.h:267
const unsigned int parse_eol
Definition pugixml.h:204
const unsigned int parse_default
Definition pugixml.h:242
const unsigned int parse_declaration
Definition pugixml.h:213
const unsigned int parse_comments
Definition pugixml.h:191
xpath_value_type
Definition pugixml.h:1189
@ xpath_type_number
Definition pugixml.h:1192
@ xpath_type_boolean
Definition pugixml.h:1194
@ xpath_type_none
Definition pugixml.h:1190
@ xpath_type_string
Definition pugixml.h:1193
@ xpath_type_node_set
Definition pugixml.h:1191
const unsigned int parse_ws_pcdata
Definition pugixml.h:198
const unsigned int parse_minimal
Definition pugixml.h:185
const unsigned int parse_ws_pcdata_single
Definition pugixml.h:221
const unsigned int format_no_escapes
Definition pugixml.h:279
PUGIXML_CHAR char_t
Definition pugixml.h:151
const int default_float_precision
Definition pugixml.h:301
std::basic_string< PUGIXML_CHAR > string_t
Definition pugixml.h:155
const unsigned int parse_doctype
Definition pugixml.h:216
Definition GML.h:111
#define PUGIXML_NULL
Definition pugixml.h:135
#define PUGIXML_DEPRECATED
Definition pugixml.h:62
#define PUGIXML_NOEXCEPT_IF_NOT_COMPACT
Definition pugixml.h:114
#define PUGIXML_FUNCTION
Definition pugixml.h:78
#define PUGIXML_NOEXCEPT
Definition pugixml.h:106
#define PUGIXML_OVERRIDE
Definition pugixml.h:124
#define PUGIXML_CLASS
Definition pugixml.h:73
#define PUGIXML_TEXT(t)
Definition pugixml.h:144
#define PUGIXML_CHAR
Definition pugixml.h:145
const char * description() const
xml_encoding encoding
Definition pugixml.h:1095
xml_parse_status status
Definition pugixml.h:1089
const char * description() const