Open
Graph Drawing
Framework

 v. 2025.10-dev (Foxglove)
 

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