soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SXml.h
1#ifndef __SXML__H__
2#define __SXML__H__
3
4#include <utilities.h>
5#include <utilities-def.h>
6#include <interface/sxml-i.h>
7#include <pugixml/pugixml.hpp>
8#include <souicoll.h>
9#include <helper/obj-ref-impl.hpp>
10
11SNSBEGIN
12
13/**
14 * @class SXmlAttr
15 * @brief Class representing an XML attribute.
16 *
17 * This class provides methods to manipulate and access XML attributes.
18 */
19class UTILITIES_API SXmlAttr : public IXmlAttr
20{
21 friend class SXmlNode;
22
23private:
24 pugi::xml_attribute _attr;
25
26private:
27 /**
28 * @brief Converts a pugi::xml_attribute to an IXmlAttr pointer.
29 *
30 * @param attr The pugi::xml_attribute to convert.
31 * @return Pointer to the converted IXmlAttr.
32 */
33 static IXmlAttr *toIXmlAttr(pugi::xml_attribute attr);
34
35public:
36 /**
37 * @brief Constructor for SXmlAttr.
38 *
39 * @param attr The pugi::xml_attribute to initialize with.
40 */
41 SXmlAttr(pugi::xml_attribute attr);
42
43 /**
44 * @brief Constructor for SXmlAttr from an IXmlAttr pointer.
45 *
46 * @param src The IXmlAttr pointer to initialize with.
47 */
48 SXmlAttr(const IXmlAttr * src);
49
50 /**
51 * @brief Copy constructor for SXmlAttr.
52 *
53 * @param src The SXmlAttr to copy.
54 */
55 SXmlAttr(const SXmlAttr& src);
56
57 /**
58 * @brief Constructor for SXmlAttr with an optional private data pointer.
59 *
60 * @param pData Pointer to private data.
61 */
62 explicit SXmlAttr(LPVOID pData = NULL);
63
64public:
65 /**
66 * @brief Gets the private data pointer.
67 *
68 * @return Pointer to the private data.
69 */
70 STDMETHOD_(LPVOID, GetPrivPtr)(THIS) SCONST OVERRIDE;
71
72 /**
73 * @brief Checks if the attribute is empty.
74 *
75 * @return TRUE if the attribute is empty, FALSE otherwise.
76 */
77 STDMETHOD_(BOOL, Empty)(THIS) SCONST OVERRIDE;
78
79 /**
80 * @brief Gets the attribute name.
81 *
82 * @return Attribute name, or "" if the attribute is empty.
83 */
84 STDMETHOD_(const wchar_t*, Name)(THIS) SCONST OVERRIDE;
85
86 /**
87 * @brief Gets the attribute value.
88 *
89 * @return Attribute value, or "" if the attribute is empty.
90 */
91 STDMETHOD_(const wchar_t*, Value)(THIS) SCONST OVERRIDE;
92
93 /**
94 * @brief Sets user data for the attribute.
95 *
96 * @param data User data to set.
97 * @return TRUE if successful, FALSE otherwise.
98 */
99 STDMETHOD_(BOOL, set_userdata)(THIS_ int data) OVERRIDE;
100
101 /**
102 * @brief Gets user data for the attribute.
103 *
104 * @return User data.
105 */
106 STDMETHOD_(int, get_userdata)(THIS) SCONST OVERRIDE;
107
108 /**
109 * @brief Gets the next attribute in the attribute list of the parent node.
110 *
111 * @return Pointer to the next attribute.
112 */
113 STDMETHOD_(IXmlAttr*, Next)(THIS) OVERRIDE;
114
115 /**
116 * @brief Gets the previous attribute in the attribute list of the parent node.
117 *
118 * @return Pointer to the previous attribute.
119 */
120 STDMETHOD_(IXmlAttr*, Prev)(THIS) OVERRIDE;
121
122 /**
123 * @brief Converts the attribute value to an integer.
124 *
125 * @param def Default value if conversion fails or attribute is empty.
126 * @return Integer value of the attribute.
127 */
128 STDMETHOD_(int, AsInt)(THIS_ int def DEF_VAL(0)) OVERRIDE;
129
130 /**
131 * @brief Converts the attribute value to an unsigned integer.
132 *
133 * @param def Default value if conversion fails or attribute is empty.
134 * @return Unsigned integer value of the attribute.
135 */
136 STDMETHOD_(unsigned int, AsUint)(THIS_ int def DEF_VAL(0)) OVERRIDE;
137
138 /**
139 * @brief Converts the attribute value to a float.
140 *
141 * @param def Default value if conversion fails or attribute is empty.
142 * @return Float value of the attribute.
143 */
144 STDMETHOD_(float, AsFloat)(THIS_ float def DEF_VAL(0.0f)) OVERRIDE;
145
146 /**
147 * @brief Converts the attribute value to a double.
148 *
149 * @param def Default value if conversion fails or attribute is empty.
150 * @return Double value of the attribute.
151 */
152 STDMETHOD_(double, AsDouble)(THIS_ double def DEF_VAL(0.0)) OVERRIDE;
153
154 /**
155 * @brief Converts the attribute value to a boolean.
156 *
157 * @param def Default value if conversion fails or attribute is empty.
158 * @return Boolean value of the attribute.
159 */
160 STDMETHOD_(BOOL, AsBool)(THIS_ BOOL def DEF_VAL(FALSE)) OVERRIDE;
161
162public:
163 /**
164 * @brief Checks if the attribute is empty.
165 *
166 * @return TRUE if the attribute is empty, FALSE otherwise.
167 */
168 operator bool() const;
169
170 /**
171 * @brief Checks if the attribute is empty.
172 *
173 * @return TRUE if the attribute is empty, FALSE otherwise.
174 */
175 bool empty() const;
176
177 /**
178 * @brief Gets the attribute name.
179 *
180 * @return Attribute name, or "" if the attribute is empty.
181 */
182 const wchar_t* name() const;
183
184 /**
185 * @brief Gets the attribute value.
186 *
187 * @return Attribute value, or "" if the attribute is empty.
188 */
189 const wchar_t* value() const;
190
191 /**
192 * @brief Gets the attribute value as a string.
193 *
194 * @param def Default value if the attribute is empty.
195 * @return Attribute value as a string.
196 */
197 const wchar_t* as_string(const wchar_t* def = L"") const;
198
199 /**
200 * @brief Converts the attribute value to an integer.
201 *
202 * @param def Default value if conversion fails or attribute is empty.
203 * @return Integer value of the attribute.
204 */
205 int as_int(int def = 0) const;
206
207 /**
208 * @brief Converts the attribute value to an unsigned integer.
209 *
210 * @param def Default value if conversion fails or attribute is empty.
211 * @return Unsigned integer value of the attribute.
212 */
213 unsigned int as_uint(unsigned int def = 0) const;
214
215 /**
216 * @brief Converts the attribute value to a double.
217 *
218 * @param def Default value if conversion fails or attribute is empty.
219 * @return Double value of the attribute.
220 */
221 double as_double(double def = 0) const;
222
223 /**
224 * @brief Converts the attribute value to a float.
225 *
226 * @param def Default value if conversion fails or attribute is empty.
227 * @return Float value of the attribute.
228 */
229 float as_float(float def = 0) const;
230
231 /**
232 * @brief Converts the attribute value to a boolean.
233 *
234 * @param def Default value if conversion fails or attribute is empty.
235 * @return Boolean value of the attribute.
236 */
237 bool as_bool(bool def = false) const;
238
239 /**
240 * @brief Sets the attribute name.
241 *
242 * @param rhs New attribute name.
243 * @return TRUE if successful, FALSE otherwise.
244 */
245 bool set_name(const wchar_t* rhs);
246
247 /**
248 * @brief Sets the attribute value.
249 *
250 * @param rhs New attribute value.
251 * @return TRUE if successful, FALSE otherwise.
252 */
253 bool set_value(const wchar_t* rhs);
254
255 /**
256 * @brief Sets the attribute value with type conversion (integer).
257 *
258 * @param rhs New attribute value.
259 * @return TRUE if successful, FALSE otherwise.
260 */
261 bool set_value(int rhs);
262
263 /**
264 * @brief Sets the attribute value with type conversion (unsigned integer).
265 *
266 * @param rhs New attribute value.
267 * @return TRUE if successful, FALSE otherwise.
268 */
269 bool set_value(unsigned int rhs);
270
271 /**
272 * @brief Sets the attribute value with type conversion (long).
273 *
274 * @param rhs New attribute value.
275 * @return TRUE if successful, FALSE otherwise.
276 */
277 bool set_value(long rhs);
278
279 /**
280 * @brief Sets the attribute value with type conversion (unsigned long).
281 *
282 * @param rhs New attribute value.
283 * @return TRUE if successful, FALSE otherwise.
284 */
285 bool set_value(unsigned long rhs);
286
287 /**
288 * @brief Sets the attribute value with type conversion (double).
289 *
290 * @param rhs New attribute value.
291 * @return TRUE if successful, FALSE otherwise.
292 */
293 bool set_value(double rhs);
294
295 /**
296 * @brief Sets the attribute value with type conversion (double with precision).
297 *
298 * @param rhs New attribute value.
299 * @param precision Precision for the conversion.
300 * @return TRUE if successful, FALSE otherwise.
301 */
302 bool set_value(double rhs, int precision);
303
304 /**
305 * @brief Sets the attribute value with type conversion (float).
306 *
307 * @param rhs New attribute value.
308 * @return TRUE if successful, FALSE otherwise.
309 */
310 bool set_value(float rhs);
311
312 /**
313 * @brief Sets the attribute value with type conversion (float with precision).
314 *
315 * @param rhs New attribute value.
316 * @param precision Precision for the conversion.
317 * @return TRUE if successful, FALSE otherwise.
318 */
319 bool set_value(float rhs, int precision);
320
321 /**
322 * @brief Sets the attribute value with type conversion (boolean).
323 *
324 * @param rhs New attribute value.
325 * @return TRUE if successful, FALSE otherwise.
326 */
327 bool set_value(bool rhs);
328
329public:
330 /**
331 * @brief Gets the next attribute in the attribute list of the parent node.
332 *
333 * @return Next attribute.
334 */
335 SXmlAttr next_attribute() const;
336
337 /**
338 * @brief Gets the previous attribute in the attribute list of the parent node.
339 *
340 * @return Previous attribute.
341 */
343};
344
345/**
346 * @class SXmlNode
347 * @brief Class representing an XML node.
348 *
349 * This class provides methods to manipulate and access XML nodes.
350 */
351class UTILITIES_API SXmlNode : public IXmlNode
352{
353 friend class SXmlDoc;
354
355private:
356 pugi::xml_node _node;
357
358private:
359 /**
360 * @brief Converts a pugi::xml_node to an IXmlNode pointer.
361 *
362 * @param node The pugi::xml_node to convert.
363 * @return Pointer to the converted IXmlNode.
364 */
365 static IXmlNode * toIXmlNode(pugi::xml_node node);
366
367public:
368 /**
369 * @brief Constructor for SXmlNode.
370 *
371 * @param node The pugi::xml_node to initialize with.
372 */
373 SXmlNode(pugi::xml_node node);
374
375 /**
376 * @brief Constructor for SXmlNode from an IXmlNode pointer.
377 *
378 * @param src The IXmlNode pointer to initialize with.
379 */
380 SXmlNode(const IXmlNode * src);
381
382 /**
383 * @brief Copy constructor for SXmlNode.
384 *
385 * @param src The SXmlNode to copy.
386 */
387 SXmlNode(const SXmlNode& src);
388
389 /**
390 * @brief Constructor for SXmlNode with an optional private data pointer.
391 *
392 * @param pData Pointer to private data.
393 */
394 explicit SXmlNode(LPVOID pData = NULL);
395
396public:
397 /**
398 * @brief Converts the node to a string representation.
399 *
400 * @param out Pointer to the output string.
401 */
402 STDMETHOD_(void, ToString)(THIS_ IStringW *out) SCONST OVERRIDE;
403
404 /**
405 * @brief Gets the private data pointer.
406 *
407 * @return Pointer to the private data.
408 */
409 STDMETHOD_(LPVOID, GetPrivPtr)(THIS) SCONST OVERRIDE;
410
411 /**
412 * @brief Checks if the node is empty.
413 *
414 * @return TRUE if the node is empty, FALSE otherwise.
415 */
416 STDMETHOD_(BOOL, Empty)(THIS) SCONST OVERRIDE;
417
418 /**
419 * @brief Gets the node name.
420 *
421 * @return Node name, or "" if the node is empty.
422 */
423 STDMETHOD_(const wchar_t*, Name)(THIS) SCONST OVERRIDE;
424
425 /**
426 * @brief Gets the node value.
427 *
428 * @return Node value, or "" if the node is empty.
429 */
430 STDMETHOD_(const wchar_t*, Value)(THIS) SCONST OVERRIDE;
431
432 /**
433 * @brief Gets the node text.
434 *
435 * @return Node text, or "" if the node is empty.
436 */
437 STDMETHOD_(const wchar_t*, Text)(THIS) SCONST OVERRIDE;
438
439 /**
440 * @brief Sets user data for the node.
441 *
442 * @param data User data to set.
443 * @return TRUE if successful, FALSE otherwise.
444 */
445 STDMETHOD_(BOOL, set_userdata)(THIS_ int data) OVERRIDE;
446
447 /**
448 * @brief Gets user data for the node.
449 *
450 * @return User data.
451 */
452 STDMETHOD_(int, get_userdata)(THIS) SCONST OVERRIDE;
453
454 /**
455 * @brief Gets an attribute by name.
456 *
457 * @param name Attribute name.
458 * @param bCaseSensitive Flag indicating case sensitivity.
459 * @return Pointer to the attribute.
460 */
461 STDMETHOD_(IXmlAttr*, Attribute)(THIS_ const wchar_t* name, BOOL bCaseSensitive) SCONST OVERRIDE;
462
463 /**
464 * @brief Gets the first attribute in the attribute list.
465 *
466 * @return Pointer to the first attribute.
467 */
468 STDMETHOD_(IXmlAttr*, FirstAttribute)(THIS) SCONST OVERRIDE;
469
470 /**
471 * @brief Gets the last attribute in the attribute list.
472 *
473 * @return Pointer to the last attribute.
474 */
475 STDMETHOD_(IXmlAttr*, LastAttribute)(THIS) SCONST OVERRIDE;
476
477 /**
478 * @brief Gets a child node by name.
479 *
480 * @param name Child node name.
481 * @param bCaseSensitive Flag indicating case sensitivity.
482 * @return Pointer to the child node.
483 */
484 STDMETHOD_(IXmlNode*, Child)(THIS_ const wchar_t* name, BOOL bCaseSensitive) SCONST OVERRIDE;
485
486 /**
487 * @brief Gets the first child node.
488 *
489 * @return Pointer to the first child node.
490 */
491 STDMETHOD_(IXmlNode*, FirstChild)(THIS) SCONST OVERRIDE;
492
493 /**
494 * @brief Gets the last child node.
495 *
496 * @return Pointer to the last child node.
497 */
498 STDMETHOD_(IXmlNode*, LastChild)(THIS) SCONST OVERRIDE;
499
500 /**
501 * @brief Gets the next sibling node.
502 *
503 * @return Pointer to the next sibling node.
504 */
505 STDMETHOD_(IXmlNode *, NextSibling)(CTHIS) SCONST OVERRIDE;
506
507 /**
508 * @brief Gets the previous sibling node.
509 *
510 * @return Pointer to the previous sibling node.
511 */
512 STDMETHOD_(IXmlNode *, PrevSibling)(CTHIS) SCONST OVERRIDE;
513
514 /**
515 * @brief Gets the next sibling node by name.
516 *
517 * @param name Sibling node name.
518 * @param bCaseSensitive Flag indicating case sensitivity.
519 * @return Pointer to the next sibling node.
520 */
521 STDMETHOD_(IXmlNode*, NextSibling2)(THIS_ const wchar_t* name, BOOL bCaseSensitive) SCONST OVERRIDE;
522
523 /**
524 * @brief Gets the previous sibling node by name.
525 *
526 * @param name Sibling node name.
527 * @param bCaseSensitive Flag indicating case sensitivity.
528 * @return Pointer to the previous sibling node.
529 */
530 STDMETHOD_(IXmlNode*, PrevSibling2)(THIS_ const wchar_t* name, BOOL bCaseSensitive) SCONST OVERRIDE;
531
532 /**
533 * @brief Appends a child node with the specified name.
534 *
535 * @param name Child node name.
536 * @return Pointer to the appended child node.
537 */
538 STDMETHOD_(IXmlNode*, AppendChild)(THIS_ const wchar_t* name) OVERRIDE {
539 return toIXmlNode(append_child(name)._node);
540 }
541
542 /**
543 * @brief Prepends a child node with the specified name.
544 *
545 * @param name Child node name.
546 * @return Pointer to the prepended child node.
547 */
548 STDMETHOD_(IXmlNode*, PrependChild)(THIS_ const wchar_t* name) OVERRIDE {
549 return toIXmlNode(prepend_child(name)._node);
550 }
551
552 /**
553 * @brief Appends a copy of the specified node as a child.
554 *
555 * @param proto Node to copy.
556 * @return Pointer to the appended child node.
557 */
558 STDMETHOD_(IXmlNode*, AppendCopyNode)(THIS_ const IXmlNode* proto) OVERRIDE {
559 return toIXmlNode(append_copy(SXmlNode(proto))._node);
560 }
561
562 /**
563 * @brief Prepends a copy of the specified node as a child.
564 *
565 * @param proto Node to copy.
566 * @return Pointer to the prepended child node.
567 */
568 STDMETHOD_(IXmlNode*, PrependCopyNode)(THIS_ const IXmlNode* proto) OVERRIDE {
569 return toIXmlNode(prepend_copy(SXmlNode(proto))._node);
570 }
571
572 /**
573 * @brief Appends an attribute with the specified name.
574 *
575 * @param name Attribute name.
576 * @return Pointer to the appended attribute.
577 */
578 STDMETHOD_(IXmlAttr*, AppendAttribute)(THIS_ const wchar_t* name) OVERRIDE {
579 return SXmlAttr::toIXmlAttr(append_attribute(name)._attr);
580 }
581
582 /**
583 * @brief Prepends an attribute with the specified name.
584 *
585 * @param name Attribute name.
586 * @return Pointer to the prepended attribute.
587 */
588 STDMETHOD_(IXmlAttr*, PrependAttribute)(THIS_ const wchar_t* name) OVERRIDE {
589 return SXmlAttr::toIXmlAttr(prepend_attribute(name)._attr);
590 }
591
592 /// @brief Appends a copy of the specified attribute to the node.
593 /// @param proto The attribute to be copied.
594 /// @return A pointer to the newly added attribute, or an empty attribute on errors.
595 STDMETHOD_(IXmlAttr*, AppendCopyAttribute)(THIS_ const IXmlAttr* proto) OVERRIDE{
596 SXmlAttr attr(proto);
597 return SXmlAttr::toIXmlAttr(append_copy(attr)._attr);
598}
599
600 /// @brief Prepends a copy of the specified attribute to the node.
601 /// @param proto The attribute to be copied.
602 /// @return A pointer to the newly added attribute, or an empty attribute on errors.
603 STDMETHOD_(IXmlAttr*, PrependCopyAttribute)(THIS_ const IXmlAttr* proto) OVERRIDE{
604 SXmlAttr attr(proto);
605 return SXmlAttr::toIXmlAttr(prepend_copy(attr)._attr);
606}
607
608STDMETHOD_(BOOL, RemoveAttribute)(THIS_ const wchar_t* name) OVERRIDE{
609 /// @brief Removes the attribute with the specified name.
610 /// @param name The name of the attribute to be removed.
611 /// @return TRUE if the attribute was successfully removed, FALSE otherwise.
612 return !!remove_attribute(name);
613}
614
615 /// @brief Removes the child node with the specified name.
616 /// @param name The name of the child node to be removed.
617 /// @return TRUE if the child node was successfully removed, FALSE otherwise.
618 STDMETHOD_(BOOL, RemoveChild)(THIS_ const wchar_t* name) OVERRIDE{
619 return !!remove_child(name);
620}
621
622 /// @brief Removes all child nodes from the node.
623 /// @return TRUE if all child nodes were successfully removed, FALSE otherwise.
624 STDMETHOD_(BOOL, RemoveAllChilden)(THIS) OVERRIDE{
625 return !!remove_children();
626}
627
628public:
629 /// @brief Checks if two SXmlNode objects are equal.
630 /// @param src The SXmlNode object to compare with.
631 /// @return TRUE if the nodes are equal, FALSE otherwise.
632 bool operator ==(const SXmlNode &src) const{
633 return _node==src._node;
634 }
635
636 /// @brief Checks if two SXmlNode objects are not equal.
637 /// @param src The SXmlNode object to compare with.
638 /// @return TRUE if the nodes are not equal, FALSE otherwise.
639 bool operator !=(const SXmlNode &src) const{
640 return _node!=src._node;
641 }
642
643 /// @brief Checks if the node is empty.
644 /// @return TRUE if the node is empty, FALSE otherwise.
645 operator bool() const;
646
647 /// @brief Checks if the node is empty.
648 /// @return TRUE if the node is empty, FALSE otherwise.
649 bool empty() const;
650
651 /// @brief Gets the type of the node.
652 /// @return The type of the node.
653 XmlNodeType type() const;
654
655 /// @brief Gets the name of the node.
656 /// @return The name of the node, or an empty string if the node is empty or has no name.
657 const wchar_t* name() const;
658
659 /// @brief Gets the value of the node.
660 /// @return The value of the node, or an empty string if the node is empty or has no value.
661 /// @note For <node>text</node>, node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes.
662 const wchar_t* value() const;
663
664 /// @brief Gets the first attribute of the node.
665 /// @return The first attribute of the node.
666 SXmlAttr first_attribute() const;
667
668 /// @brief Gets the last attribute of the node.
669 /// @return The last attribute of the node.
670 SXmlAttr last_attribute() const;
671
672 /// @brief Gets the first child node of the node.
673 /// @return The first child node of the node.
674 SXmlNode first_child() const;
675
676 /// @brief Gets the last child node of the node.
677 /// @return The last child node of the node.
678 SXmlNode last_child() const;
679
680 /// @brief Gets the next sibling node in the children list of the parent node.
681 /// @return The next sibling node.
682 SXmlNode next_sibling() const;
683
684 /// @brief Gets the previous sibling node in the children list of the parent node.
685 /// @return The previous sibling node.
686 SXmlNode previous_sibling() const;
687
688 /// @brief Gets the parent node of the node.
689 /// @return The parent node.
690 SXmlNode parent() const;
691
692 /// @brief Gets the root node of the DOM tree this node belongs to.
693 /// @return The root node.
694 SXmlNode root() const;
695
696 /// @brief Gets the child node, attribute, or next/previous sibling with the specified name.
697 /// @param name The name of the child node, attribute, or sibling.
698 /// @param bCaseSensitive Whether the search should be case-sensitive.
699 /// @return The requested node or attribute.
700 SXmlNode child(const wchar_t* name,bool bCaseSensitive=false) const;
701
702 /// @brief Gets the attribute with the specified name.
703 /// @param name The name of the attribute.
704 /// @param bCaseSensitive Whether the search should be case-sensitive.
705 /// @return The requested attribute.
706 SXmlAttr attribute(const wchar_t* name,bool bCaseSensitive=false) const;
707
708 /// @brief Gets the next sibling node with the specified name.
709 /// @param name The name of the sibling node.
710 /// @param bCaseSensitive Whether the search should be case-sensitive.
711 /// @return The next sibling node.
712 SXmlNode next_sibling(const wchar_t* name,bool bCaseSensitive=false) const;
713
714 /// @brief Gets the previous sibling node with the specified name.
715 /// @param name The name of the sibling node.
716 /// @param bCaseSensitive Whether the search should be case-sensitive.
717 /// @return The previous sibling node.
718 SXmlNode previous_sibling(const wchar_t* name,bool bCaseSensitive=false) const;
719
720 /// @brief Gets the attribute with the specified name, starting the search from a hint.
721 /// @param name The name of the attribute.
722 /// @param hint The hint attribute to start the search from.
723 /// @param bCaseSensitive Whether the search should be case-sensitive.
724 /// @return The requested attribute.
725 SXmlAttr attribute(const wchar_t* name, SXmlAttr& hint,bool bCaseSensitive=false) const;
726
727 /// @brief Gets the child value of the current node.
728 /// @return The value of the first child node of type PCDATA/CDATA.
729 const wchar_t* child_value() const;
730
731 /// @brief Gets the child value of the child node with the specified name.
732 /// @param name The name of the child node.
733 /// @param bCaseSensitive Whether the search should be case-sensitive.
734 /// @return The value of the child node.
735 const wchar_t* child_value(const wchar_t* name,bool bCaseSensitive=false) const;
736
737 /// @brief Sets the name of the node.
738 /// @param rhs The new name for the node.
739 /// @return TRUE if the name was successfully set, FALSE otherwise.
740 bool set_name(const wchar_t* rhs);
741
742 /// @brief Sets the value of the node.
743 /// @param rhs The new value for the node.
744 /// @return TRUE if the value was successfully set, FALSE otherwise.
745 bool set_value(const wchar_t* rhs);
746
747 /// @brief Adds an attribute with the specified name.
748 /// @param name The name of the attribute to be added.
749 /// @return The added attribute, or an empty attribute on errors.
750 SXmlAttr append_attribute(const wchar_t* name);
751
752 /// @brief Prepends an attribute with the specified name.
753 /// @param name The name of the attribute to be prepended.
754 /// @return The prepended attribute, or an empty attribute on errors.
755 SXmlAttr prepend_attribute(const wchar_t* name);
756
757 /// @brief Inserts an attribute with the specified name after the specified attribute.
758 /// @param name The name of the attribute to be inserted.
759 /// @param attr The attribute after which the new attribute should be inserted.
760 /// @return The inserted attribute, or an empty attribute on errors.
761 SXmlAttr insert_attribute_after(const wchar_t* name, const SXmlAttr& attr);
762
763 /// @brief Inserts an attribute with the specified name before the specified attribute.
764 /// @param name The name of the attribute to be inserted.
765 /// @param attr The attribute before which the new attribute should be inserted.
766 /// @return The inserted attribute, or an empty attribute on errors.
767 SXmlAttr insert_attribute_before(const wchar_t* name, const SXmlAttr& attr);
768
769 /// @brief Adds a copy of the specified attribute.
770 /// @param proto The attribute to be copied.
771 /// @return The added attribute, or an empty attribute on errors.
772 SXmlAttr append_copy(const SXmlAttr& proto);
773
774 /// @brief Prepends a copy of the specified attribute.
775 /// @param proto The attribute to be copied.
776 /// @return The prepended attribute, or an empty attribute on errors.
777 SXmlAttr prepend_copy(const SXmlAttr& proto);
778
779 /// @brief Inserts a copy of the specified attribute after the specified attribute.
780 /// @param proto The attribute to be copied.
781 /// @param attr The attribute after which the new attribute should be inserted.
782 /// @return The inserted attribute, or an empty attribute on errors.
783 SXmlAttr insert_copy_after(const SXmlAttr& proto, const SXmlAttr& attr);
784
785 /// @brief Inserts a copy of the specified attribute before the specified attribute.
786 /// @param proto The attribute to be copied.
787 /// @param attr The attribute before which the new attribute should be inserted.
788 /// @return The inserted attribute, or an empty attribute on errors.
789 SXmlAttr insert_copy_before(const SXmlAttr& proto, const SXmlAttr& attr);
790
791 /// @brief Adds a child node with the specified type.
792 /// @param type The type of the child node to be added.
793 /// @return The added node, or an empty node on errors.
794 SXmlNode append_child(XmlNodeType type = node_element);
795
796 /// @brief Prepends a child node with the specified type.
797 /// @param type The type of the child node to be prepended.
798 /// @return The prepended node, or an empty node on errors.
799 SXmlNode prepend_child(XmlNodeType type = node_element);
800
801 /// @brief Inserts a child node with the specified type after the specified node.
802 /// @param type The type of the child node to be inserted.
803 /// @param node The node after which the new child node should be inserted.
804 /// @return The inserted node, or an empty node on errors.
805 SXmlNode insert_child_after(XmlNodeType type, const SXmlNode& node);
806
807 /// @brief Inserts a child node with the specified type before the specified node.
808 /// @param type The type of the child node to be inserted.
809 /// @param node The node before which the new child node should be inserted.
810 /// @return The inserted node, or an empty node on errors.
811 SXmlNode insert_child_before(XmlNodeType type, const SXmlNode& node);
812
813 /// @brief Adds a child element with the specified name.
814 /// @param name The name of the child element to be added.
815 /// @return The added node, or an empty node on errors.
816 SXmlNode append_child(const wchar_t* name);
817
818 /// @brief Prepends a child element with the specified name.
819 /// @param name The name of the child element to be prepended.
820 /// @return The prepended node, or an empty node on errors.
821 SXmlNode prepend_child(const wchar_t* name);
822
823 /// @brief Inserts a child element with the specified name after the specified node.
824 /// @param name The name of the child element to be inserted.
825 /// @param node The node after which the new child element should be inserted.
826 /// @return The inserted node, or an empty node on errors.
827 SXmlNode insert_child_after(const wchar_t* name, const SXmlNode& node);
828
829 /// @brief Inserts a child element with the specified name before the specified node.
830 /// @param name The name of the child element to be inserted.
831 /// @param node The node before which the new child element should be inserted.
832 /// @return The inserted node, or an empty node on errors.
833 SXmlNode insert_child_before(const wchar_t* name, const SXmlNode& node);
834
835 /// @brief Adds a copy of the specified node as a child.
836 /// @param proto The node to be copied.
837 /// @return The added node, or an empty node on errors.
838 SXmlNode append_copy(const SXmlNode& proto);
839
840 /// @brief Prepends a copy of the specified node as a child.
841 /// @param proto The node to be copied.
842 /// @return The prepended node, or an empty node on errors.
843 SXmlNode prepend_copy(const SXmlNode& proto);
844
845 /// @brief Inserts a copy of the specified node as a child after the specified node.
846 /// @param proto The node to be copied.
847 /// @param node The node after which the new child node should be inserted.
848 /// @return The inserted node, or an empty node on errors.
849 SXmlNode insert_copy_after(const SXmlNode& proto, const SXmlNode& node);
850
851 /// @brief Inserts a copy of the specified node as a child before the specified node.
852 /// @param proto The node to be copied.
853 /// @param node The node before which the new child node should be inserted.
854 /// @return The inserted node, or an empty node on errors.
855 SXmlNode insert_copy_before(const SXmlNode& proto, const SXmlNode& node);
856
857 /// @brief Moves the specified node to become a child of this node.
858 /// @param moved The node to be moved.
859 /// @return The moved node, or an empty node on errors.
860 SXmlNode append_move(const SXmlNode& moved);
861
862 /// @brief Prepends the specified node to become a child of this node.
863 /// @param moved The node to be moved.
864 /// @return The moved node, or an empty node on errors.
865 SXmlNode prepend_move(const SXmlNode& moved);
866
867 /// @brief Inserts the specified node to become a child of this node after the specified node.
868 /// @param moved The node to be moved.
869 /// @param node The node after which the new child node should be inserted.
870 /// @return The moved node, or an empty node on errors.
871 SXmlNode insert_move_after(const SXmlNode& moved, const SXmlNode& node);
872
873 /// @brief Inserts the specified node to become a child of this node before the specified node.
874 /// @param moved The node to be moved.
875 /// @param node The node before which the new child node should be inserted.
876 /// @return The moved node, or an empty node on errors.
877 SXmlNode insert_move_before(const SXmlNode& moved, const SXmlNode& node);
878
879 /// @brief Removes the specified attribute.
880 /// @param a The attribute to be removed.
881 /// @return TRUE if the attribute was successfully removed, FALSE otherwise.
882 bool remove_attribute(const SXmlAttr& a);
883
884 /// @brief Removes the attribute with the specified name.
885 /// @param name The name of the attribute to be removed.
886 /// @return TRUE if the attribute was successfully removed, FALSE otherwise.
887 bool remove_attribute(const wchar_t* name);
888
889 /// @brief Removes all attributes from the node.
890 /// @return TRUE if all attributes were successfully removed, FALSE otherwise.
891 bool remove_attributes();
892
893 /// @brief Removes the specified child node.
894 /// @param n The child node to be removed.
895 /// @return TRUE if the child node was successfully removed, FALSE otherwise.
896 bool remove_child(const SXmlNode& n);
897
898 /// @brief Removes the child node with the specified name.
899 /// @param name The name of the child node to be removed.
900 /// @return TRUE if the child node was successfully removed, FALSE otherwise.
901 bool remove_child(const wchar_t* name);
902
903 /// @brief Removes all child nodes from the node.
904 /// @return TRUE if all child nodes were successfully removed, FALSE otherwise.
905 bool remove_children();
906};
907
908/**
909 * @brief Implementation of IXmlDoc.
910 */
911class UTILITIES_API SXmlDoc : public TObjRefImpl<IXmlDoc>
912{
913 friend class SXmlAttr;
914 friend class SXmlNode;
915private:
916 /// @brief Pointer to the underlying pugi::xml_document.
917 pugi::xml_document *_doc;
918
919 /// @brief Result of the last parsing operation.
920 mutable pugi::xml_parse_result _result;
921
922 /// @brief Map type for storing attributes.
923 typedef SMap<pugi::xml_attribute_struct *, SXmlAttr*> AttrMap;
924
925 /// @brief Map for storing attributes.
926 AttrMap *m_attrMap;
927
928 /// @brief Map type for storing nodes.
929 typedef SMap<pugi::xml_node_struct *, SXmlNode*> NodeMap;
930
931 /// @brief Map for storing nodes.
932 NodeMap *m_nodeMap;
933
934 /// @brief Converts a pugi::xml_attribute_struct to an IXmlAttr.
935 /// @param pAttr The attribute structure to convert.
936 /// @return A pointer to the converted attribute.
937 IXmlAttr * toIXmlAttr(pugi::xml_attribute_struct *pAttr);
938
939 /// @brief Converts a pugi::xml_node_struct to an IXmlNode.
940 /// @param pNode The node structure to convert.
941 /// @return A pointer to the converted node.
942 IXmlNode * toIXmlNode(pugi::xml_node_struct* pNode);
943
944 /// @brief Clears the attribute and node maps.
945 void clearMap();
946
947public:
948 /// @brief Constructor for SXmlDoc.
949 SXmlDoc();
950
951 /// @brief Destructor for SXmlDoc.
952 ~SXmlDoc();
953
954public:
955 /// @brief Retrieves a private pointer associated with the document.
956 /// @return The private pointer.
957 STDMETHOD_(LPVOID, GetPrivPtr)(THIS) SCONST OVERRIDE;
958
959 /// @brief Resets the document, removing all nodes.
960 STDMETHOD_(void, Reset)(THIS) OVERRIDE;
961
962 /// @brief Copies the contents of another document into this document.
963 /// @param proto The document to copy from.
964 STDMETHOD_(void, Copy)(THIS_ const IXmlDoc* proto) OVERRIDE;
965
966 /// @brief Loads the document from a zero-terminated string.
967 /// @param contents The string containing the XML data.
968 /// @param options Parsing options.
969 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
970 STDMETHOD_(BOOL, LoadString)(THIS_ const wchar_t* contents, unsigned int options) OVERRIDE;
971
972 /// @brief Loads the document from a file (ANSI version).
973 /// @param path The path to the file.
974 /// @param options Parsing options.
975 /// @param encoding The encoding of the file.
976 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
977 STDMETHOD_(BOOL, LoadFileA)(THIS_ const char* path, unsigned int options, XmlEncoding encoding) OVERRIDE;
978
979 /// @brief Loads the document from a file (Unicode version).
980 /// @param path The path to the file.
981 /// @param options Parsing options.
982 /// @param encoding The encoding of the file.
983 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
984 STDMETHOD_(BOOL, LoadFileW)(THIS_ const wchar_t* path, unsigned int options, XmlEncoding encoding) OVERRIDE;
985
986 /// @brief Loads the document from a buffer.
987 /// @param contents The buffer containing the XML data.
988 /// @param size The size of the buffer.
989 /// @param options Parsing options.
990 /// @param encoding The encoding of the buffer.
991 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
992 STDMETHOD_(BOOL, LoadBuffer)(THIS_ const void* contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE;
993
994 /// @brief Loads the document from a buffer using in-place parsing.
995 /// @param contents The buffer containing the XML data.
996 /// @param size The size of the buffer.
997 /// @param options Parsing options.
998 /// @param encoding The encoding of the buffer.
999 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
1000 /// @note You should ensure that buffer data will persist throughout the document's lifetime and free the buffer memory manually once the document is destroyed.
1001 STDMETHOD_(BOOL, LoadBufferInplace)(THIS_ void* contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE;
1002
1003 /// @brief Loads the document from a buffer using in-place parsing with automatic buffer management.
1004 /// @param contents The buffer containing the XML data.
1005 /// @param size The size of the buffer.
1006 /// @param options Parsing options.
1007 /// @param encoding The encoding of the buffer.
1008 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
1009 /// @note You should allocate the buffer with pugixml allocation function; document will free the buffer when it is no longer needed.
1010 STDMETHOD_(BOOL, LoadBufferInplaceOwn)(THIS_ void* contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE;
1011
1012 /// @brief Retrieves the result of the last parsing operation.
1013 /// @param pResult The parse result to store.
1014 STDMETHOD_(void, GetParseResult)(THIS_ XmlParseResult *pResult) SCONST OVERRIDE;
1015
1016 /// @brief Saves the XML document to a writer.
1017 /// @param f The file pointer to write to.
1018 /// @note Semantics is slightly different from xml_node::print, see documentation for details.
1019 STDMETHOD_(void, SaveBinary)(THIS_ FILE *f) SCONST OVERRIDE;
1020
1021 /// @brief Saves the XML document to a file (ANSI version).
1022 /// @param path The path to the file.
1023 /// @param indent The indentation string.
1024 /// @param flags Saving flags.
1025 /// @param encoding The encoding of the file.
1026 /// @return TRUE if the document was successfully saved, FALSE otherwise.
1027 STDMETHOD_(BOOL, SaveFileA)(THIS_ const char* path, const wchar_t* indent, unsigned int flags, XmlEncoding encoding) SCONST OVERRIDE;
1028
1029 /// @brief Saves the XML document to a file (Unicode version).
1030 /// @param path The path to the file.
1031 /// @param indent The indentation string.
1032 /// @param flags Saving flags.
1033 /// @param encoding The encoding of the file.
1034 /// @return TRUE if the document was successfully saved, FALSE otherwise.
1035 STDMETHOD_(BOOL, SaveFileW)(THIS_ const wchar_t* path, const wchar_t* indent, unsigned int flags, XmlEncoding encoding) SCONST OVERRIDE;
1036
1037 /// @brief Retrieves the root node of the document.
1038 /// @return The root node.
1039 STDMETHOD_(IXmlNode *, Root)(THIS) SCONST OVERRIDE;
1040
1041public:
1042 /// @brief Loads the document from a zero-terminated string.
1043 /// @param contents The string containing the XML data.
1044 /// @param options Parsing options.
1045 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
1046 bool load_string(const wchar_t* contents, unsigned int options = xml_parse_default);
1047
1048 /// @brief Loads the document from a file (ANSI version).
1049 /// @param path The path to the file.
1050 /// @param options Parsing options.
1051 /// @param encoding The encoding of the file.
1052 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
1053 bool load_file(const char* path, unsigned int options = xml_parse_default, XmlEncoding encoding = enc_auto);
1054
1055 /// @brief Loads the document from a file (Unicode version).
1056 /// @param path The path to the file.
1057 /// @param options Parsing options.
1058 /// @param encoding The encoding of the file.
1059 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
1060 bool load_file(const wchar_t* path, unsigned int options = xml_parse_default, XmlEncoding encoding = enc_auto);
1061
1062 /// @brief Loads the document from a buffer.
1063 /// @param contents The buffer containing the XML data.
1064 /// @param size The size of the buffer.
1065 /// @param options Parsing options.
1066 /// @param encoding The encoding of the buffer.
1067 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
1068 bool load_buffer(const void* contents, size_t size, unsigned int options = xml_parse_default, XmlEncoding encoding = enc_auto);
1069
1070 /// @brief Loads the document from a buffer using in-place parsing.
1071 /// @param contents The buffer containing the XML data.
1072 /// @param size The size of the buffer.
1073 /// @param options Parsing options.
1074 /// @param encoding The encoding of the buffer.
1075 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
1076 /// @note You should ensure that buffer data will persist throughout the document's lifetime and free the buffer memory manually once the document is destroyed.
1077 bool load_buffer_inplace(void* contents, size_t size, unsigned int options = xml_parse_default, XmlEncoding encoding = enc_auto);
1078
1079 /// @brief Loads the document from a buffer using in-place parsing with automatic buffer management.
1080 /// @param contents The buffer containing the XML data.
1081 /// @param size The size of the buffer.
1082 /// @param options Parsing options.
1083 /// @param encoding The encoding of the buffer.
1084 /// @return TRUE if the document was successfully loaded, FALSE otherwise.
1085 /// @note You should allocate the buffer with pugixml allocation function; document will free the buffer when it is no longer needed.
1086 bool load_buffer_inplace_own(void* contents, size_t size, unsigned int options = xml_parse_default, XmlEncoding encoding = enc_auto);
1087
1088 /// @brief Saves the XML document to a file (ANSI version).
1089 /// @param path The path to the file.
1090 /// @param indent The indentation string.
1091 /// @param flags Saving flags.
1092 /// @param encoding The encoding of the file.
1093 /// @return TRUE if the document was successfully saved, FALSE otherwise.
1094 bool save_file(const char* path, const wchar_t* indent = L"\t", unsigned int flags = xml_parse_default, XmlEncoding encoding = enc_auto) const;
1095
1096 /// @brief Saves the XML document to a file (Unicode version).
1097 /// @param path The path to the file.
1098 /// @param indent The indentation string.
1099 /// @param flags Saving flags.
1100 /// @param encoding The encoding of the file.
1101 /// @return TRUE if the document was successfully saved, FALSE otherwise.
1102 bool save_file(const wchar_t* path, const wchar_t* indent = L"\t", unsigned int flags = xml_parse_default, XmlEncoding encoding = enc_auto) const;
1103
1104 /// @brief Retrieves the root node of the document.
1105 /// @return The root node.
1106 SXmlNode root() const;
1107
1108 /// @brief Retrieves the error description for a given XML status.
1109 /// @param status The XML status.
1110 /// @return The error description.
1111 static const char * GetErrDesc(XmlStatus status);
1112};
1113
1114
1115SNSEND
1116
1117#endif // __SXML__H__
Class representing an XML attribute.
Definition SXml.h:20
const wchar_t * Value() SCONST OVERRIDE
Gets the attribute value.
Definition SXml.cpp:48
float as_float(float def=0) const
Converts the attribute value to a float.
Definition SXml.cpp:115
SXmlAttr next_attribute() const
Gets the next attribute in the attribute list of the parent node.
Definition SXml.cpp:180
SXmlAttr(pugi::xml_attribute attr)
Constructor for SXmlAttr.
Definition SXml.cpp:16
float AsFloat(float def=0.0f) OVERRIDE
Converts the attribute value to a float.
Definition SXml.cpp:200
IXmlAttr * Prev() OVERRIDE
Gets the previous attribute in the attribute list of the parent node.
Definition SXml.cpp:69
BOOL set_userdata(int data) OVERRIDE
Sets user data for the attribute.
Definition SXml.cpp:53
const wchar_t * Name() SCONST OVERRIDE
Gets the attribute name.
Definition SXml.cpp:43
int AsInt(int def=0) OVERRIDE
Converts the attribute value to an integer.
Definition SXml.cpp:190
int as_int(int def=0) const
Converts the attribute value to an integer.
Definition SXml.cpp:100
int get_userdata() SCONST OVERRIDE
Gets user data for the attribute.
Definition SXml.cpp:58
bool set_value(const wchar_t *rhs)
Sets the attribute value.
Definition SXml.cpp:130
bool set_name(const wchar_t *rhs)
Sets the attribute name.
Definition SXml.cpp:125
double AsDouble(double def=0.0) OVERRIDE
Converts the attribute value to a double.
Definition SXml.cpp:205
const wchar_t * name() const
Gets the attribute name.
Definition SXml.cpp:85
BOOL Empty() SCONST OVERRIDE
Checks if the attribute is empty.
Definition SXml.cpp:38
const wchar_t * as_string(const wchar_t *def=L"") const
Gets the attribute value as a string.
Definition SXml.cpp:95
unsigned int as_uint(unsigned int def=0) const
Converts the attribute value to an unsigned integer.
Definition SXml.cpp:105
bool as_bool(bool def=false) const
Converts the attribute value to a boolean.
Definition SXml.cpp:120
IXmlAttr * Next() OVERRIDE
Gets the next attribute in the attribute list of the parent node.
Definition SXml.cpp:63
double as_double(double def=0) const
Converts the attribute value to a double.
Definition SXml.cpp:110
SXmlAttr previous_attribute() const
Gets the previous attribute in the attribute list of the parent node.
Definition SXml.cpp:185
unsigned int AsUint(int def=0) OVERRIDE
Converts the attribute value to an unsigned integer.
Definition SXml.cpp:195
LPVOID GetPrivPtr() SCONST OVERRIDE
Gets the private data pointer.
Definition SXml.cpp:33
bool empty() const
Checks if the attribute is empty.
Definition SXml.cpp:80
const wchar_t * value() const
Gets the attribute value.
Definition SXml.cpp:90
BOOL AsBool(BOOL def=FALSE) OVERRIDE
Converts the attribute value to a boolean.
Definition SXml.cpp:210
IXmlNode * Root() SCONST OVERRIDE
Retrieves the root node of the document.
Definition SXml.cpp:627
bool load_buffer_inplace(void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer using in-place parsing.
Definition SXml.cpp:732
void Copy(const IXmlDoc *proto) OVERRIDE
Copies the contents of another document into this document.
Definition SXml.cpp:692
BOOL LoadBufferInplaceOwn(void *contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a buffer using in-place parsing with automatic buffer management.
Definition SXml.cpp:648
bool load_buffer_inplace_own(void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer using in-place parsing with automatic buffer management.
Definition SXml.cpp:738
SXmlDoc()
Constructor for SXmlDoc.
Definition SXml.cpp:611
BOOL LoadFileA(const char *path, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a file (ANSI version).
Definition SXml.cpp:672
bool save_file(const char *path, const wchar_t *indent=L"\t", unsigned int flags=xml_parse_default, XmlEncoding encoding=enc_auto) const
Saves the XML document to a file (ANSI version).
Definition SXml.cpp:744
static const char * GetErrDesc(XmlStatus status)
Retrieves the error description for a given XML status.
Definition SXml.cpp:759
void GetParseResult(XmlParseResult *pResult) SCONST OVERRIDE
Retrieves the result of the last parsing operation.
Definition SXml.cpp:684
SXmlNode root() const
Retrieves the root node of the document.
Definition SXml.cpp:754
BOOL SaveFileW(const wchar_t *path, const wchar_t *indent, unsigned int flags, XmlEncoding encoding) SCONST OVERRIDE
Saves the XML document to a file (Unicode version).
Definition SXml.cpp:632
BOOL LoadString(const wchar_t *contents, unsigned int options) OVERRIDE
Loads the document from a zero-terminated string.
Definition SXml.cpp:678
BOOL LoadFileW(const wchar_t *path, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a file (Unicode version).
Definition SXml.cpp:666
BOOL SaveFileA(const char *path, const wchar_t *indent, unsigned int flags, XmlEncoding encoding) SCONST OVERRIDE
Saves the XML document to a file (ANSI version).
Definition SXml.cpp:637
BOOL LoadBufferInplace(void *contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a buffer using in-place parsing.
Definition SXml.cpp:654
bool load_string(const wchar_t *contents, unsigned int options=xml_parse_default)
Loads the document from a zero-terminated string.
Definition SXml.cpp:708
BOOL LoadBuffer(const void *contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a buffer.
Definition SXml.cpp:660
void Reset() OVERRIDE
Resets the document, removing all nodes.
Definition SXml.cpp:697
void SaveBinary(FILE *f) SCONST OVERRIDE
Saves the XML document to a writer.
Definition SXml.cpp:643
bool load_buffer(const void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer.
Definition SXml.cpp:726
LPVOID GetPrivPtr() SCONST OVERRIDE
Retrieves a private pointer associated with the document.
Definition SXml.cpp:703
bool load_file(const char *path, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a file (ANSI version).
Definition SXml.cpp:714
Class representing an XML node.
Definition SXml.h:352
BOOL RemoveAttribute(const wchar_t *name) OVERRIDE
Removes an attribute by name.
Definition SXml.h:608
IXmlNode * PrependCopyNode(const IXmlNode *proto) OVERRIDE
Prepends a copy of the specified node as a child.
Definition SXml.h:568
IXmlNode * PrevSibling2(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets the previous sibling node by name.
Definition SXml.cpp:334
LPVOID GetPrivPtr() SCONST OVERRIDE
Gets the private data pointer.
Definition SXml.cpp:245
IXmlAttr * LastAttribute() SCONST OVERRIDE
Gets the last attribute in the attribute list.
Definition SXml.cpp:292
IXmlAttr * AppendCopyAttribute(const IXmlAttr *proto) OVERRIDE
Appends a copy of the specified attribute to the node.
Definition SXml.h:595
BOOL RemoveChild(const wchar_t *name) OVERRIDE
Removes the child node with the specified name.
Definition SXml.h:618
SXmlAttr append_copy(const SXmlAttr &proto)
Adds a copy of the specified attribute.
Definition SXml.cpp:478
const wchar_t * Name() SCONST OVERRIDE
Gets the node name.
Definition SXml.cpp:255
void ToString(IStringW *out) SCONST OVERRIDE
Converts the node to a string representation.
Definition SXml.cpp:238
const wchar_t * Value() SCONST OVERRIDE
Gets the node value.
Definition SXml.cpp:260
IXmlAttr * FirstAttribute() SCONST OVERRIDE
Gets the first attribute in the attribute list.
Definition SXml.cpp:286
bool remove_attribute(const SXmlAttr &a)
Removes the specified attribute.
Definition SXml.cpp:578
IXmlNode * NextSibling2(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets the next sibling node by name.
Definition SXml.cpp:328
IXmlNode * PrependChild(const wchar_t *name) OVERRIDE
Prepends a child node with the specified name.
Definition SXml.h:548
const wchar_t * name() const
Gets the name of the node.
Definition SXml.cpp:363
bool remove_children()
Removes all child nodes from the node.
Definition SXml.cpp:603
IXmlAttr * PrependAttribute(const wchar_t *name) OVERRIDE
Prepends an attribute with the specified name.
Definition SXml.h:588
BOOL RemoveAllChilden() OVERRIDE
Removes all child nodes from the node.
Definition SXml.h:624
SXmlAttr append_attribute(const wchar_t *name)
Adds an attribute with the specified name.
Definition SXml.cpp:458
SXmlNode prepend_child(XmlNodeType type=node_element)
Prepends a child node with the specified type.
Definition SXml.cpp:528
int get_userdata() SCONST OVERRIDE
Gets user data for the node.
Definition SXml.cpp:275
IXmlNode * NextSibling() SCONST OVERRIDE
Gets the next sibling node.
Definition SXml.cpp:316
IXmlNode * PrevSibling() SCONST OVERRIDE
Gets the previous sibling node.
Definition SXml.cpp:322
bool remove_child(const SXmlNode &n)
Removes the specified child node.
Definition SXml.cpp:593
IXmlNode * AppendCopyNode(const IXmlNode *proto) OVERRIDE
Appends a copy of the specified node as a child.
Definition SXml.h:558
IXmlNode * Child(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets a child node by name.
Definition SXml.cpp:298
IXmlAttr * Attribute(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets an attribute by name.
Definition SXml.cpp:280
SXmlAttr prepend_attribute(const wchar_t *name)
Prepends an attribute with the specified name.
Definition SXml.cpp:463
IXmlNode * LastChild() SCONST OVERRIDE
Gets the last child node.
Definition SXml.cpp:310
IXmlNode * FirstChild() SCONST OVERRIDE
Gets the first child node.
Definition SXml.cpp:304
IXmlAttr * PrependCopyAttribute(const IXmlAttr *proto) OVERRIDE
Prepends a copy of the specified attribute to the node.
Definition SXml.h:603
SXmlAttr prepend_copy(const SXmlAttr &proto)
Prepends a copy of the specified attribute.
Definition SXml.cpp:488
IXmlAttr * AppendAttribute(const wchar_t *name) OVERRIDE
Appends an attribute with the specified name.
Definition SXml.h:578
const wchar_t * Text() SCONST OVERRIDE
Gets the node text.
Definition SXml.cpp:265
SXmlNode append_child(XmlNodeType type=node_element)
Adds a child node with the specified type.
Definition SXml.cpp:518
BOOL Empty() SCONST OVERRIDE
Checks if the node is empty.
Definition SXml.cpp:250
SXmlNode(pugi::xml_node node)
Constructor for SXmlNode.
Definition SXml.cpp:227
BOOL set_userdata(int data) OVERRIDE
Sets user data for the node.
Definition SXml.cpp:270
IXmlNode * AppendChild(const wchar_t *name) OVERRIDE
Appends a child node with the specified name.
Definition SXml.h:538
Interface for XML attributes.
Definition sxml-i.h:17
Interface for XML Document.
Definition sxml-i.h:472
Interface for XML nodes.
Definition sxml-i.h:128
Bitfield structure for font style attributes.