aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
tinyxml.cpp
Go to the documentation of this file.
1/*
2www.sourceforge.net/projects/tinyxml
3Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason
4(www.grinninglizard.com)
5
6This software is provided 'as-is', without any express or implied
7warranty. In no event will the authors be held liable for any
8damages arising from the use of this software.
9
10Permission is granted to anyone to use this software for any
11purpose, including commercial applications, and to alter it and
12redistribute it freely, subject to the following restrictions:
13
141. The origin of this software must not be misrepresented; you must
15not claim that you wrote the original software. If you use this
16software in a product, an acknowledgment in the product documentation
17would be appreciated but is not required.
18
192. Altered source versions must be plainly marked as such, and
20must not be misrepresented as being the original software.
21
223. This notice may not be removed or altered from any source
23distribution.
24*/
25#include "tinyxml.h"
26
27#include <ctype.h>
28
29#ifdef TIXML_USE_STL
30#include <iostream>
31#include <sstream>
32#endif
33
35
36// Microsoft compiler security
37FILE* TiXmlFOpen(const char* filename, const char* mode) {
38#if defined(_MSC_VER) && (_MSC_VER >= 1400)
39 FILE* fp = 0;
40 errno_t err = fopen_s(&fp, filename, mode);
41
42 if (!err && fp) return fp;
43
44 return 0;
45#else
46 return fopen(filename, mode);
47#endif
48}
49
51 int i = 0;
52
53 while (i < (int)str.length()) {
54 unsigned char c = (unsigned char)str[i];
55
56 if (c == '&' && i < ((int)str.length() - 2) && str[i + 1] == '#' &&
57 str[i + 2] == 'x') {
58 // Hexadecimal character reference.
59 // Pass through unchanged.
60 // &#xA9; -- copyright symbol, for example.
61 //
62 // The -1 is a bug fix from Rob Laveaux. It keeps
63 // an overflow from happening if there is no ';'.
64 // There are actually 2 ways to exit this loop -
65 // while fails (error case) and break (semicolon found).
66 // However, there is no mechanism (currently) for
67 // this function to return an error.
68 while (i < (int)str.length() - 1) {
69 outString->append(str.c_str() + i, 1);
70 ++i;
71
72 if (str[i] == ';') break;
73 }
74 } else if (c == '&') {
75 outString->append(entity[0].str, entity[0].strLength);
76 ++i;
77 } else if (c == '<') {
78 outString->append(entity[1].str, entity[1].strLength);
79 ++i;
80 } else if (c == '>') {
81 outString->append(entity[2].str, entity[2].strLength);
82 ++i;
83 } else if (c == '\"') {
84 outString->append(entity[3].str, entity[3].strLength);
85 ++i;
86 } else if (c == '\'') {
87 outString->append(entity[4].str, entity[4].strLength);
88 ++i;
89 } else if (c < 32) {
90 // Easy pass at non-alpha/numeric/symbol
91 // Below 32 is symbolic.
92 char buf[32];
93
94#if defined(TIXML_SNPRINTF)
95 TIXML_SNPRINTF(buf, sizeof(buf), "&#x%02X;", (unsigned)(c & 0xff));
96#else
97 snprintf(buf, 32, "&#x%02X;", (unsigned)(c & 0xff));
98#endif
99
100 //*ME: warning C4267: convert 'size_t' to 'int'
101 //*ME: Int-Cast to make compiler happy ...
102 outString->append(buf, (int)strlen(buf));
103 ++i;
104 } else {
105 // char realc = (char) c;
106 // outString->append( &realc, 1 );
107 *outString += (char)c; // somewhat more efficient function call.
108 ++i;
109 }
110 }
111}
112
114 : TiXmlBase() {
115 parent = 0;
116 type = _type;
117 firstChild = 0;
118 lastChild = 0;
119 prev = 0;
120 next = 0;
121}
122
124 TiXmlNode* node = firstChild;
125 TiXmlNode* temp = 0;
126
127 while (node) {
128 temp = node;
129 node = node->next;
130 delete temp;
131 }
132}
133
134void TiXmlNode::CopyTo(TiXmlNode* target) const {
135 target->SetValue(value.c_str());
136 target->userData = userData;
137}
138
140 TiXmlNode* node = firstChild;
141 TiXmlNode* temp = 0;
142
143 while (node) {
144 temp = node;
145 node = node->next;
146 delete temp;
147 }
148
149 firstChild = 0;
150 lastChild = 0;
151}
152
154 assert(node->parent == 0 || node->parent == this);
155 assert(node->GetDocument() == 0 || node->GetDocument() == this->GetDocument());
156
157 if (node->Type() == TiXmlNode::DOCUMENT) {
158 delete node;
159
160 if (GetDocument())
163
164 return 0;
165 }
166
167 node->parent = this;
168
169 node->prev = lastChild;
170 node->next = 0;
171
172 if (lastChild)
173 lastChild->next = node;
174 else
175 firstChild = node; // it was an empty list.
176
177 lastChild = node;
178 return node;
179}
180
182 if (addThis.Type() == TiXmlNode::DOCUMENT) {
183 if (GetDocument())
186
187 return 0;
188 }
189
190 TiXmlNode* node = addThis.Clone();
191
192 if (!node) return 0;
193
194 return LinkEndChild(node);
195}
196
198 const TiXmlNode& addThis) {
199 if (!beforeThis || beforeThis->parent != this) {
200 return 0;
201 }
202
203 if (addThis.Type() == TiXmlNode::DOCUMENT) {
204 if (GetDocument())
207
208 return 0;
209 }
210
211 TiXmlNode* node = addThis.Clone();
212
213 if (!node) return 0;
214
215 node->parent = this;
216
217 node->next = beforeThis;
218 node->prev = beforeThis->prev;
219
220 if (beforeThis->prev) {
221 beforeThis->prev->next = node;
222 } else {
223 assert(firstChild == beforeThis);
224 firstChild = node;
225 }
226
227 beforeThis->prev = node;
228 return node;
229}
230
232 const TiXmlNode& addThis) {
233 if (!afterThis || afterThis->parent != this) {
234 return 0;
235 }
236
237 if (addThis.Type() == TiXmlNode::DOCUMENT) {
238 if (GetDocument())
241
242 return 0;
243 }
244
245 TiXmlNode* node = addThis.Clone();
246
247 if (!node) return 0;
248
249 node->parent = this;
250
251 node->prev = afterThis;
252 node->next = afterThis->next;
253
254 if (afterThis->next) {
255 afterThis->next->prev = node;
256 } else {
257 assert(lastChild == afterThis);
258 lastChild = node;
259 }
260
261 afterThis->next = node;
262 return node;
263}
264
266 const TiXmlNode& withThis) {
267 if (replaceThis->parent != this) return 0;
268
269 TiXmlNode* node = withThis.Clone();
270
271 if (!node) return 0;
272
273 node->next = replaceThis->next;
274 node->prev = replaceThis->prev;
275
276 if (replaceThis->next)
277 replaceThis->next->prev = node;
278 else
279 lastChild = node;
280
281 if (replaceThis->prev)
282 replaceThis->prev->next = node;
283 else
284 firstChild = node;
285
286 delete replaceThis;
287 node->parent = this;
288 return node;
289}
290
292 if (removeThis->parent != this) {
293 assert(0);
294 return false;
295 }
296
297 if (removeThis->next)
298 removeThis->next->prev = removeThis->prev;
299 else
300 lastChild = removeThis->prev;
301
302 if (removeThis->prev)
303 removeThis->prev->next = removeThis->next;
304 else
305 firstChild = removeThis->next;
306
307 delete removeThis;
308 return true;
309}
310
311const TiXmlNode* TiXmlNode::FirstChild(const char* _value) const {
312 const TiXmlNode* node;
313
314 for (node = firstChild; node; node = node->next) {
315 if (strcmp(node->Value(), _value) == 0) return node;
316 }
317
318 return 0;
319}
320
321const TiXmlNode* TiXmlNode::LastChild(const char* _value) const {
322 const TiXmlNode* node;
323
324 for (node = lastChild; node; node = node->prev) {
325 if (strcmp(node->Value(), _value) == 0) return node;
326 }
327
328 return 0;
329}
330
331const TiXmlNode* TiXmlNode::IterateChildren(const TiXmlNode* previous) const {
332 if (!previous) {
333 return FirstChild();
334 } else {
335 assert(previous->parent == this);
336 return previous->NextSibling();
337 }
338}
339
341 const TiXmlNode* previous) const {
342 if (!previous) {
343 return FirstChild(val);
344 } else {
345 assert(previous->parent == this);
346 return previous->NextSibling(val);
347 }
348}
349
350const TiXmlNode* TiXmlNode::NextSibling(const char* _value) const {
351 const TiXmlNode* node;
352
353 for (node = next; node; node = node->next) {
354 if (strcmp(node->Value(), _value) == 0) return node;
355 }
356
357 return 0;
358}
359
360const TiXmlNode* TiXmlNode::PreviousSibling(const char* _value) const {
361 const TiXmlNode* node;
362
363 for (node = prev; node; node = node->prev) {
364 if (strcmp(node->Value(), _value) == 0) return node;
365 }
366
367 return 0;
368}
369
370void TiXmlElement::RemoveAttribute(const char* name) {
371#ifdef TIXML_USE_STL
372 TIXML_STRING str(name);
373 TiXmlAttribute* node = attributeSet.Find(str);
374#else
375 TiXmlAttribute* node = attributeSet.Find(name);
376#endif
377
378 if (node) {
379 attributeSet.Remove(node);
380 delete node;
381 }
382}
383
385 const TiXmlNode* node;
386
387 for (node = FirstChild(); node; node = node->NextSibling()) {
388 if (node->ToElement()) return node->ToElement();
389 }
390
391 return 0;
392}
393
394const TiXmlElement* TiXmlNode::FirstChildElement(const char* _value) const {
395 const TiXmlNode* node;
396
397 for (node = FirstChild(_value); node; node = node->NextSibling(_value)) {
398 if (node->ToElement()) return node->ToElement();
399 }
400
401 return 0;
402}
403
405 const TiXmlNode* node;
406
407 for (node = NextSibling(); node; node = node->NextSibling()) {
408 if (node->ToElement()) return node->ToElement();
409 }
410
411 return 0;
412}
413
414const TiXmlElement* TiXmlNode::NextSiblingElement(const char* _value) const {
415 const TiXmlNode* node;
416
417 for (node = NextSibling(_value); node; node = node->NextSibling(_value)) {
418 if (node->ToElement()) return node->ToElement();
419 }
420
421 return 0;
422}
423
425 const TiXmlNode* node;
426
427 for (node = this; node; node = node->parent) {
428 if (node->ToDocument()) return node->ToDocument();
429 }
430
431 return 0;
432}
433
434TiXmlElement::TiXmlElement(const char* _value)
436 firstChild = lastChild = 0;
437 value = _value;
438}
439
440#ifdef TIXML_USE_STL
441TiXmlElement::TiXmlElement(const std::string& _value)
443 firstChild = lastChild = 0;
444 value = _value;
445}
446#endif
447
450 firstChild = lastChild = 0;
451 copy.CopyTo(this);
452}
453
455 ClearThis();
456 base.CopyTo(this);
457}
458
460
462 Clear();
463
464 while (attributeSet.First()) {
465 TiXmlAttribute* node = attributeSet.First();
466 attributeSet.Remove(node);
467 delete node;
468 }
469}
470
471const char* TiXmlElement::Attribute(const char* name) const {
472 const TiXmlAttribute* node = attributeSet.Find(name);
473
474 if (node) return node->Value();
475
476 return 0;
477}
478
479#ifdef TIXML_USE_STL
480const std::string* TiXmlElement::Attribute(const std::string& name) const {
481 const TiXmlAttribute* node = attributeSet.Find(name);
482
483 if (node) return &node->ValueStr();
484
485 return 0;
486}
487#endif
488
489const char* TiXmlElement::Attribute(const char* name, int* i) const {
490 const char* s = Attribute(name);
491
492 if (i) {
493 if (s) {
494 *i = atoi(s);
495 } else {
496 *i = 0;
497 }
498 }
499
500 return s;
501}
502
503#ifdef TIXML_USE_STL
504const std::string* TiXmlElement::Attribute(const std::string& name, int* i) const {
505 const std::string* s = Attribute(name);
506
507 if (i) {
508 if (s) {
509 *i = atoi(s->c_str());
510 } else {
511 *i = 0;
512 }
513 }
514
515 return s;
516}
517#endif
518
519const char* TiXmlElement::Attribute(const char* name, double* d) const {
520 const char* s = Attribute(name);
521
522 if (d) {
523 if (s) {
524 *d = atof(s);
525 } else {
526 *d = 0;
527 }
528 }
529
530 return s;
531}
532
533#ifdef TIXML_USE_STL
534const std::string* TiXmlElement::Attribute(const std::string& name,
535 double* d) const {
536 const std::string* s = Attribute(name);
537
538 if (d) {
539 if (s) {
540 *d = atof(s->c_str());
541 } else {
542 *d = 0;
543 }
544 }
545
546 return s;
547}
548#endif
549
550int TiXmlElement::QueryIntAttribute(const char* name, int* ival) const {
551 const TiXmlAttribute* node = attributeSet.Find(name);
552
553 if (!node) return TIXML_NO_ATTRIBUTE;
554
555 return node->QueryIntValue(ival);
556}
557
558#ifdef TIXML_USE_STL
559int TiXmlElement::QueryIntAttribute(const std::string& name, int* ival) const {
560 const TiXmlAttribute* node = attributeSet.Find(name);
561
562 if (!node) return TIXML_NO_ATTRIBUTE;
563
564 return node->QueryIntValue(ival);
565}
566#endif
567
568int TiXmlElement::QueryDoubleAttribute(const char* name, double* dval) const {
569 const TiXmlAttribute* node = attributeSet.Find(name);
570
571 if (!node) return TIXML_NO_ATTRIBUTE;
572
573 return node->QueryDoubleValue(dval);
574}
575
576#ifdef TIXML_USE_STL
577int TiXmlElement::QueryDoubleAttribute(const std::string& name,
578 double* dval) const {
579 const TiXmlAttribute* node = attributeSet.Find(name);
580
581 if (!node) return TIXML_NO_ATTRIBUTE;
582
583 return node->QueryDoubleValue(dval);
584}
585#endif
586
587void TiXmlElement::SetAttribute(const char* name, int val) {
588 char buf[64];
589#if defined(TIXML_SNPRINTF)
590 TIXML_SNPRINTF(buf, sizeof(buf), "%d", val);
591#else
592 snprintf(buf, 64, "%d", val);
593#endif
594 SetAttribute(name, buf);
595}
596
597#ifdef TIXML_USE_STL
598void TiXmlElement::SetAttribute(const std::string& name, int val) {
599 std::ostringstream oss;
600 oss << val;
601 SetAttribute(name, oss.str());
602}
603#endif
604
605void TiXmlElement::SetDoubleAttribute(const char* name, double val) {
606 char buf[256];
607#if defined(TIXML_SNPRINTF)
608 TIXML_SNPRINTF(buf, sizeof(buf), "%f", val);
609#else
610 snprintf(buf, 256, "%f", val);
611#endif
612 SetAttribute(name, buf);
613}
614
615void TiXmlElement::SetAttribute(const char* cname, const char* cvalue) {
616#ifdef TIXML_USE_STL
617 TIXML_STRING _name(cname);
618 TIXML_STRING _value(cvalue);
619#else
620 const char* _name = cname;
621 const char* _value = cvalue;
622#endif
623
624 TiXmlAttribute* node = attributeSet.Find(_name);
625
626 if (node) {
627 node->SetValue(_value);
628 return;
629 }
630
631 TiXmlAttribute* attrib = new TiXmlAttribute(cname, cvalue);
632
633 if (attrib) {
634 attributeSet.Add(attrib);
635 } else {
636 TiXmlDocument* document = GetDocument();
637
638 if (document)
640 }
641}
642
643#ifdef TIXML_USE_STL
644void TiXmlElement::SetAttribute(const std::string& name,
645 const std::string& _value) {
646 TiXmlAttribute* node = attributeSet.Find(name);
647
648 if (node) {
649 node->SetValue(_value);
650 return;
651 }
652
653 TiXmlAttribute* attrib = new TiXmlAttribute(name, _value);
654
655 if (attrib) {
656 attributeSet.Add(attrib);
657 } else {
658 TiXmlDocument* document = GetDocument();
659
660 if (document)
662 }
663}
664#endif
665
666void TiXmlElement::Print(FILE* cfile, int depth) const {
667 int i;
668 assert(cfile);
669
670 for (i = 0; i < depth; i++) {
671 fprintf(cfile, " ");
672 }
673
674 fprintf(cfile, "<%s", value.c_str());
675
676 const TiXmlAttribute* attrib;
677
678 for (attrib = attributeSet.First(); attrib; attrib = attrib->Next()) {
679 fprintf(cfile, " ");
680 attrib->Print(cfile, depth);
681 }
682
683 // There are 3 different formatting approaches:
684 // 1) An element without children is printed as a <foo /> node
685 // 2) An element with only a text child is printed as <foo> text </foo>
686 // 3) An element with children is printed on multiple lines.
687 TiXmlNode* node;
688
689 if (!firstChild) {
690 fprintf(cfile, " />");
691 } else if (firstChild == lastChild && firstChild->ToText()) {
692 fprintf(cfile, ">");
693 firstChild->Print(cfile, depth + 1);
694 fprintf(cfile, "</%s>", value.c_str());
695 } else {
696 fprintf(cfile, ">");
697
698 for (node = firstChild; node; node = node->NextSibling()) {
699 if (!node->ToText()) {
700 fprintf(cfile, "\n");
701 }
702
703 node->Print(cfile, depth + 1);
704 }
705
706 fprintf(cfile, "\n");
707
708 for (i = 0; i < depth; ++i) {
709 fprintf(cfile, " ");
710 }
711
712 fprintf(cfile, "</%s>", value.c_str());
713 }
714}
715
717 // superclass:
718 TiXmlNode::CopyTo(target);
719
720 // Element class:
721 // Clone the attributes, then clone the children.
722 const TiXmlAttribute* attribute = 0;
723
724 for (attribute = attributeSet.First(); attribute;
725 attribute = attribute->Next()) {
726 target->SetAttribute(attribute->Name(), attribute->Value());
727 }
728
729 TiXmlNode* node = 0;
730
731 for (node = firstChild; node; node = node->NextSibling()) {
732 target->LinkEndChild(node->Clone());
733 }
734}
735
736bool TiXmlElement::Accept(TiXmlVisitor* visitor) const {
737 if (visitor->VisitEnter(*this, attributeSet.First())) {
738 for (const TiXmlNode* node = FirstChild(); node; node = node->NextSibling()) {
739 if (!node->Accept(visitor)) break;
740 }
741 }
742
743 return visitor->VisitExit(*this);
744}
745
747 TiXmlElement* clone = new TiXmlElement(Value());
748
749 if (!clone) return 0;
750
751 CopyTo(clone);
752 return clone;
753}
754
755const char* TiXmlElement::GetText() const {
756 const TiXmlNode* child = this->FirstChild();
757
758 if (child) {
759 const TiXmlText* childText = child->ToText();
760
761 if (childText) {
762 return childText->Value();
763 }
764 }
765
766 return 0;
767}
768
775
776TiXmlDocument::TiXmlDocument(const char* documentName)
778 tabsize = 4;
779 useMicrosoftBOM = false;
780 value = documentName;
781 ClearError();
782}
783
784#ifdef TIXML_USE_STL
785TiXmlDocument::TiXmlDocument(const std::string& documentName)
787 tabsize = 4;
788 useMicrosoftBOM = false;
789 value = documentName;
790 ClearError();
791}
792#endif
793
798
800 Clear();
801 copy.CopyTo(this);
802}
803
805 // See STL_STRING_BUG below.
806 // StringToBuffer buf( value );
807
808 return LoadFile(Value(), encoding);
809}
810
812 // See STL_STRING_BUG below.
813 // StringToBuffer buf( value );
814 //
815 // if ( buf.buffer && SaveFile( buf.buffer ) )
816 // return true;
817 //
818 // return false;
819 return SaveFile(Value());
820}
821
822bool TiXmlDocument::LoadFile(const char* _filename, TiXmlEncoding encoding) {
823 // There was a really terrifying little bug here. The code:
824 // value = filename
825 // in the STL case, cause the assignment method of the std::string to
826 // be called. What is strange, is that the std::string had the same
827 // address as it's c_str() method, and so bad things happen. Looks
828 // like a bug in the Microsoft STL implementation.
829 // Add an extra string to avoid the crash.
830 TIXML_STRING filename(_filename);
831 value = filename;
832
833 // reading in binary mode so that tinyxml can normalize the EOL
834 FILE* file = TiXmlFOpen(value.c_str(), "rb");
835
836 if (file) {
837 bool result = LoadFile(file, encoding);
838 fclose(file);
839 return result;
840 } else {
842 return false;
843 }
844}
845
846bool TiXmlDocument::LoadFile(FILE* file, TiXmlEncoding encoding) {
847 if (!file) {
849 return false;
850 }
851
852 // Delete the existing data:
853 Clear();
854 location.Clear();
855
856 // Get the file size, so we can pre-allocate the string. HUGE speed impact.
857 long length = 0;
858 fseek(file, 0, SEEK_END);
859 length = ftell(file);
860 fseek(file, 0, SEEK_SET);
861
862 // Strange case, but good to handle up front.
863 if (length <= 0) {
865 return false;
866 }
867
868 // If we have a file, assume it is all one big XML file, and read it in.
869 // The document parser may decide the document ends sooner than the entire
870 // file,
871 // however.
872 TIXML_STRING data;
873 data.reserve(length);
874
875 // Subtle bug here. TinyXml did use fgets. But from the XML spec:
876 // 2.11 End-of-Line Handling
877 // <snip>
878 // <quote>
879 // ...the XML processor MUST behave as if it normalized all line breaks in
880 // external
881 // parsed entities (including the document entity) on input, before parsing,
882 // by
883 // translating
884 // both the two-character sequence #xD #xA and any #xD that is not followed by
885 // #xA
886 // to
887 // a single #xA character.
888 // </quote>
889 //
890 // It is not clear fgets does that, and certainly isn't clear it works cross
891 // platform.
892 // Generally, you expect fgets to translate from the convention of the OS to
893 // the
894 // c/unix
895 // convention, and not work generally.
896
897 /*
898 while( fgets( buf, sizeof(buf), file ) )
899 {
900 data += buf;
901 }
902 */
903
904 char* buf = new char[length + 1];
905 buf[0] = 0;
906
907 if (fread(buf, length, 1, file) != 1) {
908 delete[] buf;
910 return false;
911 }
912
913 const char* lastPos = buf;
914 const char* p = buf;
915
916 buf[length] = 0;
917
918 while (*p) {
919 assert(p < (buf + length));
920
921 if (*p == 0xa) {
922 // Newline character. No special rules for this. Append all the characters
923 // since the last string, and include the newline.
924 data.append(lastPos, (p - lastPos + 1)); // append, include the newline
925 ++p; // move past the newline
926 lastPos = p; // and point to the new buffer (may be 0)
927 assert(p <= (buf + length));
928 } else if (*p == 0xd) {
929 // Carriage return. Append what we have so far, then
930 // handle moving forward in the buffer.
931 if ((p - lastPos) > 0) {
932 data.append(lastPos, p - lastPos); // do not add the CR
933 }
934
935 data += (char)0xa; // a proper newline
936
937 if (*(p + 1) == 0xa) {
938 // Carriage return - new line sequence
939 p += 2;
940 lastPos = p;
941 assert(p <= (buf + length));
942 } else {
943 // it was followed by something else...that is presumably characters
944 // again.
945 ++p;
946 lastPos = p;
947 assert(p <= (buf + length));
948 }
949 } else {
950 ++p;
951 }
952 }
953
954 // Handle any left over characters.
955 if (p - lastPos) {
956 data.append(lastPos, p - lastPos);
957 }
958
959 delete[] buf;
960 buf = 0;
961
962 Parse(data.c_str(), 0, encoding);
963
964 if (Error())
965 return false;
966 else
967 return true;
968}
969
970bool TiXmlDocument::SaveFile(const char* filename) const {
971 // The old c stuff lives on...
972 FILE* fp = TiXmlFOpen(filename, "w");
973
974 if (fp) {
975 bool result = SaveFile(fp);
976 fclose(fp);
977 return result;
978 }
979
980 return false;
981}
982
983bool TiXmlDocument::SaveFile(FILE* fp) const {
984 if (useMicrosoftBOM) {
985 const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
986 const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
987 const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
988
989 fputc(TIXML_UTF_LEAD_0, fp);
990 fputc(TIXML_UTF_LEAD_1, fp);
991 fputc(TIXML_UTF_LEAD_2, fp);
992 }
993
994 Print(fp, 0);
995 return (ferror(fp) == 0);
996}
997
999 TiXmlNode::CopyTo(target);
1000
1001 target->error = error;
1002 target->errorId = errorId;
1003 target->errorDesc = errorDesc;
1004 target->tabsize = tabsize;
1005 target->errorLocation = errorLocation;
1007
1008 TiXmlNode* node = 0;
1009
1010 for (node = firstChild; node; node = node->NextSibling()) {
1011 target->LinkEndChild(node->Clone());
1012 }
1013}
1014
1016 TiXmlDocument* clone = new TiXmlDocument();
1017
1018 if (!clone) return 0;
1019
1020 CopyTo(clone);
1021 return clone;
1022}
1023
1024void TiXmlDocument::Print(FILE* cfile, int depth) const {
1025 assert(cfile);
1026
1027 for (const TiXmlNode* node = FirstChild(); node; node = node->NextSibling()) {
1028 node->Print(cfile, depth);
1029 fprintf(cfile, "\n");
1030 }
1031}
1032
1034 if (visitor->VisitEnter(*this)) {
1035 for (const TiXmlNode* node = FirstChild(); node; node = node->NextSibling()) {
1036 if (!node->Accept(visitor)) break;
1037 }
1038 }
1039
1040 return visitor->VisitExit(*this);
1041}
1042
1044 // We are using knowledge of the sentinel. The sentinel
1045 // have a value or name.
1046 if (next->value.empty() && next->name.empty()) return 0;
1047
1048 return next;
1049}
1050
1051/*
1052TiXmlAttribute* TiXmlAttribute::Next()
1053{
1054 // We are using knowledge of the sentinel. The sentinel
1055 // have a value or name.
1056 if ( next->value.empty() && next->name.empty() )
1057 return 0;
1058 return next;
1059}
1060*/
1061
1063 // We are using knowledge of the sentinel. The sentinel
1064 // have a value or name.
1065 if (prev->value.empty() && prev->name.empty()) return 0;
1066
1067 return prev;
1068}
1069
1070/*
1071TiXmlAttribute* TiXmlAttribute::Previous()
1072{
1073 // We are using knowledge of the sentinel. The sentinel
1074 // have a value or name.
1075 if ( prev->value.empty() && prev->name.empty() )
1076 return 0;
1077 return prev;
1078}
1079*/
1080
1081void TiXmlAttribute::Print(FILE* cfile, int /*depth*/, TIXML_STRING* str) const {
1082 TIXML_STRING n, v;
1083
1084 EncodeString(name, &n);
1085 EncodeString(value, &v);
1086
1087 if (value.find('\"') == TIXML_STRING::npos) {
1088 if (cfile) {
1089 fprintf(cfile, "%s=\"%s\"", n.c_str(), v.c_str());
1090 }
1091
1092 if (str) {
1093 (*str) += n;
1094 (*str) += "=\"";
1095 (*str) += v;
1096 (*str) += "\"";
1097 }
1098 } else {
1099 if (cfile) {
1100 fprintf(cfile, "%s='%s'", n.c_str(), v.c_str());
1101 }
1102
1103 if (str) {
1104 (*str) += n;
1105 (*str) += "='";
1106 (*str) += v;
1107 (*str) += "'";
1108 }
1109 }
1110}
1111
1112int TiXmlAttribute::QueryIntValue(int* ival) const {
1113 if (TIXML_SSCANF(value.c_str(), "%d", ival) == 1) return TIXML_SUCCESS;
1114
1115 return TIXML_WRONG_TYPE;
1116}
1117
1118int TiXmlAttribute::QueryDoubleValue(double* dval) const {
1119 if (TIXML_SSCANF(value.c_str(), "%lf", dval) == 1) return TIXML_SUCCESS;
1120
1121 return TIXML_WRONG_TYPE;
1122}
1123
1125 char buf[64];
1126#if defined(TIXML_SNPRINTF)
1127 TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
1128#else
1129 snprintf(buf, 64, "%d", _value);
1130#endif
1131 SetValue(buf);
1132}
1133
1135 char buf[256];
1136#if defined(TIXML_SNPRINTF)
1137 TIXML_SNPRINTF(buf, sizeof(buf), "%g", _value);
1138#else
1139 snprintf(buf, 256, "%lf", _value);
1140#endif
1141 SetValue(buf);
1142}
1143
1144int TiXmlAttribute::IntValue() const { return atoi(value.c_str()); }
1145
1146double TiXmlAttribute::DoubleValue() const { return atof(value.c_str()); }
1147
1150 copy.CopyTo(this);
1151}
1152
1154 Clear();
1155 base.CopyTo(this);
1156}
1157
1158void TiXmlComment::Print(FILE* cfile, int depth) const {
1159 assert(cfile);
1160
1161 for (int i = 0; i < depth; i++) {
1162 fprintf(cfile, " ");
1163 }
1164
1165 fprintf(cfile, "<!--%s-->", value.c_str());
1166}
1167
1169 TiXmlNode::CopyTo(target);
1170}
1171
1173 return visitor->Visit(*this);
1174}
1175
1177 TiXmlComment* clone = new TiXmlComment();
1178
1179 if (!clone) return 0;
1180
1181 CopyTo(clone);
1182 return clone;
1183}
1184
1185void TiXmlText::Print(FILE* cfile, int depth) const {
1186 assert(cfile);
1187
1188 if (cdata) {
1189 int i;
1190 fprintf(cfile, "\n");
1191
1192 for (i = 0; i < depth; i++) {
1193 fprintf(cfile, " ");
1194 }
1195
1196 fprintf(cfile, "<![CDATA[%s]]>\n", value.c_str()); // unformatted output
1197 } else {
1198 TIXML_STRING buffer;
1199 EncodeString(value, &buffer);
1200 fprintf(cfile, "%s", buffer.c_str());
1201 }
1202}
1203
1204void TiXmlText::CopyTo(TiXmlText* target) const {
1205 TiXmlNode::CopyTo(target);
1206 target->cdata = cdata;
1207}
1208
1209bool TiXmlText::Accept(TiXmlVisitor* visitor) const {
1210 return visitor->Visit(*this);
1211}
1212
1214 TiXmlText* clone = 0;
1215 clone = new TiXmlText("");
1216
1217 if (!clone) return 0;
1218
1219 CopyTo(clone);
1220 return clone;
1221}
1222
1224 const char* _encoding,
1225 const char* _standalone)
1227 version = _version;
1228 encoding = _encoding;
1229 standalone = _standalone;
1230}
1231
1232#ifdef TIXML_USE_STL
1233TiXmlDeclaration::TiXmlDeclaration(const std::string& _version,
1234 const std::string& _encoding,
1235 const std::string& _standalone)
1237 version = _version;
1238 encoding = _encoding;
1239 standalone = _standalone;
1240}
1241#endif
1242
1247
1249 Clear();
1250 copy.CopyTo(this);
1251}
1252
1253void TiXmlDeclaration::Print(FILE* cfile, int /*depth*/, TIXML_STRING* str) const {
1254 if (cfile) fprintf(cfile, "<?xml ");
1255
1256 if (str) (*str) += "<?xml ";
1257
1258 if (!version.empty()) {
1259 if (cfile) fprintf(cfile, "version=\"%s\" ", version.c_str());
1260
1261 if (str) {
1262 (*str) += "version=\"";
1263 (*str) += version;
1264 (*str) += "\" ";
1265 }
1266 }
1267
1268 if (!encoding.empty()) {
1269 if (cfile) fprintf(cfile, "encoding=\"%s\" ", encoding.c_str());
1270
1271 if (str) {
1272 (*str) += "encoding=\"";
1273 (*str) += encoding;
1274 (*str) += "\" ";
1275 }
1276 }
1277
1278 if (!standalone.empty()) {
1279 if (cfile) fprintf(cfile, "standalone=\"%s\" ", standalone.c_str());
1280
1281 if (str) {
1282 (*str) += "standalone=\"";
1283 (*str) += standalone;
1284 (*str) += "\" ";
1285 }
1286 }
1287
1288 if (cfile) fprintf(cfile, "?>");
1289
1290 if (str) (*str) += "?>";
1291}
1292
1294 TiXmlNode::CopyTo(target);
1295
1296 target->version = version;
1297 target->encoding = encoding;
1298 target->standalone = standalone;
1299}
1300
1302 return visitor->Visit(*this);
1303}
1304
1306 TiXmlDeclaration* clone = new TiXmlDeclaration();
1307
1308 if (!clone) return 0;
1309
1310 CopyTo(clone);
1311 return clone;
1312}
1313
1315 const char* _href)
1317 type = _type;
1318 href = _href;
1319}
1320
1321#ifdef TIXML_USE_STL
1323 const std::string& _href)
1325 type = _type;
1326 href = _href;
1327}
1328#endif
1329
1335
1337 Clear();
1338 copy.CopyTo(this);
1339}
1340
1342 int /*depth*/,
1343 TIXML_STRING* str) const {
1344 if (cfile) fprintf(cfile, "<?xml-stylesheet ");
1345
1346 if (str) (*str) += "<?xml-stylesheet ";
1347
1348 if (!type.empty()) {
1349 if (cfile) fprintf(cfile, "type=\"%s\" ", type.c_str());
1350
1351 if (str) {
1352 (*str) += "type=\"";
1353 (*str) += type;
1354 (*str) += "\" ";
1355 }
1356 }
1357
1358 if (!href.empty()) {
1359 if (cfile) fprintf(cfile, "href=\"%s\" ", href.c_str());
1360
1361 if (str) {
1362 (*str) += "href=\"";
1363 (*str) += href;
1364 (*str) += "\" ";
1365 }
1366 }
1367
1368 if (cfile) fprintf(cfile, "?>");
1369
1370 if (str) (*str) += "?>";
1371}
1372
1374 TiXmlNode::CopyTo(target);
1375
1376 target->type = type;
1377 target->href = href;
1378}
1379
1381 return visitor->Visit(*this);
1382}
1383
1386
1387 if (!clone) return 0;
1388
1389 CopyTo(clone);
1390 return clone;
1391}
1392
1393void TiXmlUnknown::Print(FILE* cfile, int depth) const {
1394 for (int i = 0; i < depth; i++)
1395 fprintf(cfile, " ");
1396
1397 fprintf(cfile, "<%s>", value.c_str());
1398}
1399
1401 TiXmlNode::CopyTo(target);
1402}
1403
1405 return visitor->Visit(*this);
1406}
1407
1409 TiXmlUnknown* clone = new TiXmlUnknown();
1410
1411 if (!clone) return 0;
1412
1413 CopyTo(clone);
1414 return clone;
1415}
1416
1421
1423 assert(sentinel.next == &sentinel);
1424 assert(sentinel.prev == &sentinel);
1425}
1426
1428#ifdef TIXML_USE_STL
1429 assert(!Find(
1430 TIXML_STRING(addMe->Name()))); // Shouldn't be multiply adding to the set.
1431#else
1432 assert(!Find(addMe->Name())); // Shouldn't be multiply adding to the set.
1433#endif
1434
1435 addMe->next = &sentinel;
1436 addMe->prev = sentinel.prev;
1437
1438 sentinel.prev->next = addMe;
1439 sentinel.prev = addMe;
1440}
1441
1443 TiXmlAttribute* node;
1444
1445 for (node = sentinel.next; node != &sentinel; node = node->next) {
1446 if (node == removeMe) {
1447 node->prev->next = node->next;
1448 node->next->prev = node->prev;
1449 node->next = 0;
1450 node->prev = 0;
1451 return;
1452 }
1453 }
1454
1455 assert(0); // we tried to remove a non-linked attribute.
1456}
1457
1458#ifdef TIXML_USE_STL
1459const TiXmlAttribute* TiXmlAttributeSet::Find(const std::string& name) const {
1460 for (const TiXmlAttribute* node = sentinel.next; node != &sentinel;
1461 node = node->next) {
1462 if (node->name == name) return node;
1463 }
1464
1465 return 0;
1466}
1467
1468/*
1469TiXmlAttribute* TiXmlAttributeSet::Find( const std::string& name )
1470{
1471 for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node =
1472node->next )
1473 {
1474 if ( node->name == name )
1475 return node;
1476 }
1477 return 0;
1478}
1479*/
1480#endif
1481
1482const TiXmlAttribute* TiXmlAttributeSet::Find(const char* name) const {
1483 for (const TiXmlAttribute* node = sentinel.next; node != &sentinel;
1484 node = node->next) {
1485 if (strcmp(node->name.c_str(), name) == 0) return node;
1486 }
1487
1488 return 0;
1489}
1490
1491/*
1492TiXmlAttribute* TiXmlAttributeSet::Find( const char* name )
1493{
1494 for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node =
1495node->next )
1496 {
1497 if ( strcmp( node->name.c_str(), name ) == 0 )
1498 return node;
1499 }
1500 return 0;
1501}
1502*/
1503
1504#ifdef TIXML_USE_STL
1505std::istream& operator>>(std::istream& in, TiXmlNode& base) {
1506 TIXML_STRING tag;
1507 tag.reserve(8 * 1000);
1508 base.StreamIn(&in, &tag);
1509
1510 base.Parse(tag.c_str(), 0, TIXML_DEFAULT_ENCODING);
1511 return in;
1512}
1513#endif
1514
1515#ifdef TIXML_USE_STL
1516std::ostream& operator<<(std::ostream& out, const TiXmlNode& base) {
1517 TiXmlPrinter printer;
1518 printer.SetStreamPrinting();
1519 base.Accept(&printer);
1520 out << printer.Str();
1521
1522 return out;
1523}
1524
1525std::string& operator<<(std::string& out, const TiXmlNode& base) {
1526 TiXmlPrinter printer;
1527 printer.SetStreamPrinting();
1528 base.Accept(&printer);
1529 out.append(printer.Str());
1530
1531 return out;
1532}
1533#endif
1534
1536 if (node) {
1537 TiXmlNode* child = node->FirstChild();
1538
1539 if (child) return TiXmlHandle(child);
1540 }
1541
1542 return TiXmlHandle(0);
1543}
1544
1545TiXmlHandle TiXmlHandle::FirstChild(const char* value) const {
1546 if (node) {
1547 TiXmlNode* child = node->FirstChild(value);
1548
1549 if (child) return TiXmlHandle(child);
1550 }
1551
1552 return TiXmlHandle(0);
1553}
1554
1556 if (node) {
1557 TiXmlElement* child = node->FirstChildElement();
1558
1559 if (child) return TiXmlHandle(child);
1560 }
1561
1562 return TiXmlHandle(0);
1563}
1564
1566 if (node) {
1567 TiXmlElement* child = node->FirstChildElement(value);
1568
1569 if (child) return TiXmlHandle(child);
1570 }
1571
1572 return TiXmlHandle(0);
1573}
1574
1576 if (node) {
1577 int i;
1578 TiXmlNode* child = node->FirstChild();
1579
1580 for (i = 0; child && i < count; child = child->NextSibling(), ++i) {
1581 // nothing
1582 }
1583
1584 if (child) return TiXmlHandle(child);
1585 }
1586
1587 return TiXmlHandle(0);
1588}
1589
1590TiXmlHandle TiXmlHandle::Child(const char* value, int count) const {
1591 if (node) {
1592 int i;
1593 TiXmlNode* child = node->FirstChild(value);
1594
1595 for (i = 0; child && i < count; child = child->NextSibling(value), ++i) {
1596 // nothing
1597 }
1598
1599 if (child) return TiXmlHandle(child);
1600 }
1601
1602 return TiXmlHandle(0);
1603}
1604
1606 if (node) {
1607 int i;
1608 TiXmlElement* child = node->FirstChildElement();
1609
1610 for (i = 0; child && i < count; child = child->NextSiblingElement(), ++i) {
1611 // nothing
1612 }
1613
1614 if (child) return TiXmlHandle(child);
1615 }
1616
1617 return TiXmlHandle(0);
1618}
1619
1620TiXmlHandle TiXmlHandle::ChildElement(const char* value, int count) const {
1621 if (node) {
1622 int i;
1623 TiXmlElement* child = node->FirstChildElement(value);
1624
1625 for (i = 0; child && i < count;
1626 child = child->NextSiblingElement(value), ++i) {
1627 // nothing
1628 }
1629
1630 if (child) return TiXmlHandle(child);
1631 }
1632
1633 return TiXmlHandle(0);
1634}
1635
1636bool TiXmlPrinter::VisitEnter(const TiXmlDocument&) { return true; }
1637
1638bool TiXmlPrinter::VisitExit(const TiXmlDocument&) { return true; }
1639
1641 const TiXmlAttribute* firstAttribute) {
1642 DoIndent();
1643 buffer += "<";
1644 buffer += element.Value();
1645
1646 for (const TiXmlAttribute* attrib = firstAttribute; attrib;
1647 attrib = attrib->Next()) {
1648 buffer += " ";
1649 attrib->Print(0, 0, &buffer);
1650 }
1651
1652 if (!element.FirstChild()) {
1653 buffer += " />";
1654 DoLineBreak();
1655 } else {
1656 buffer += ">";
1657
1658 if (element.FirstChild()->ToText() &&
1659 element.LastChild() == element.FirstChild() &&
1660 element.FirstChild()->ToText()->CDATA() == false) {
1661 simpleTextPrint = true;
1662 // no DoLineBreak()!
1663 } else {
1664 DoLineBreak();
1665 }
1666 }
1667
1668 ++depth;
1669 return true;
1670}
1671
1673 --depth;
1674
1675 if (!element.FirstChild()) {
1676 // nothing.
1677 } else {
1678 if (simpleTextPrint) {
1679 simpleTextPrint = false;
1680 } else {
1681 DoIndent();
1682 }
1683
1684 buffer += "</";
1685 buffer += element.Value();
1686 buffer += ">";
1687 DoLineBreak();
1688 }
1689
1690 return true;
1691}
1692
1694 if (text.CDATA()) {
1695 DoIndent();
1696 buffer += "<![CDATA[";
1697 buffer += text.Value();
1698 buffer += "]]>";
1699 DoLineBreak();
1700 } else if (simpleTextPrint) {
1701 TIXML_STRING str;
1702 TiXmlBase::EncodeString(text.ValueTStr(), &str);
1703 buffer += str;
1704 } else {
1705 DoIndent();
1706 TIXML_STRING str;
1707 TiXmlBase::EncodeString(text.ValueTStr(), &str);
1708 buffer += str;
1709 DoLineBreak();
1710 }
1711
1712 return true;
1713}
1714
1715bool TiXmlPrinter::Visit(const TiXmlDeclaration& declaration) {
1716 DoIndent();
1717 declaration.Print(0, 0, &buffer);
1718 DoLineBreak();
1719 return true;
1720}
1721
1722bool TiXmlPrinter::Visit(const TiXmlComment& comment) {
1723 DoIndent();
1724 buffer += "<!--";
1725 buffer += comment.Value();
1726 buffer += "-->";
1727 DoLineBreak();
1728 return true;
1729}
1730
1731bool TiXmlPrinter::Visit(const TiXmlUnknown& unknown) {
1732 DoIndent();
1733 buffer += "<";
1734 buffer += unknown.Value();
1735 buffer += ">";
1736 DoLineBreak();
1737 return true;
1738}
1739
1741 DoIndent();
1742 stylesheet.Print(0, 0, &buffer);
1743 DoLineBreak();
1744 return true;
1745}
TiXmlAttribute sentinel
Definition tinyxml.h:1088
const TiXmlAttribute * Find(const char *_name) const
Definition tinyxml.cpp:1482
void Add(TiXmlAttribute *attribute)
Definition tinyxml.cpp:1427
void Remove(TiXmlAttribute *attribute)
Definition tinyxml.cpp:1442
An attribute is a name-value pair.
Definition tinyxml.h:915
void SetDoubleValue(double _value)
Set the value from a double.
Definition tinyxml.cpp:1134
const char * Value() const
Return the value of this attribute.
Definition tinyxml.h:947
void SetValue(const char *_value)
Set the value.
Definition tinyxml.h:979
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition tinyxml.h:1016
int QueryIntValue(int *_value) const
QueryIntValue examines the value string.
Definition tinyxml.cpp:1112
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
Definition tinyxml.cpp:1118
void SetIntValue(int _value)
Set the value from an integer.
Definition tinyxml.cpp:1124
const char * Name() const
Return the name of this attribute.
Definition tinyxml.h:944
double DoubleValue() const
Return the value of this attribute, converted to a double.
Definition tinyxml.cpp:1146
TiXmlAttribute()
Construct an empty attribute.
Definition tinyxml.h:920
TiXmlAttribute * prev
Definition tinyxml.h:1030
int IntValue() const
Return the value of this attribute, converted to an integer.
Definition tinyxml.cpp:1144
const std::string & ValueStr() const
Return the value of this attribute.
Definition tinyxml.h:951
TiXmlAttribute * next
Definition tinyxml.h:1031
TIXML_STRING value
Definition tinyxml.h:1029
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Definition tinyxml.cpp:1043
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
Definition tinyxml.cpp:1062
TIXML_STRING name
Definition tinyxml.h:1028
TiXmlCursor location
Definition tinyxml.h:410
virtual void Print(FILE *cfile, int depth) const =0
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
friend class TiXmlNode
Definition tinyxml.h:216
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
Expands entities in a string.
Definition tinyxml.cpp:50
static bool condenseWhiteSpace
Definition tinyxml.h:445
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
@ TIXML_ERROR_DOCUMENT_TOP_ONLY
Definition tinyxml.h:321
@ TIXML_ERROR_OUT_OF_MEMORY
Definition tinyxml.h:308
@ TIXML_ERROR_DOCUMENT_EMPTY
Definition tinyxml.h:318
@ TIXML_ERROR_OPENING_FILE
Definition tinyxml.h:307
static Entity entity[NUM_ENTITY]
Definition tinyxml.h:44
void * userData
Field containing a generic user pointer.
Definition tinyxml.h:413
friend class TiXmlElement
Definition tinyxml.h:217
TiXmlBase()
Definition tinyxml.h:221
An XML comment.
Definition tinyxml.h:1330
virtual TiXmlNode * Clone() const
Returns a copy of this Comment.
Definition tinyxml.cpp:1176
void operator=(const TiXmlComment &base)
Definition tinyxml.cpp:1153
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition tinyxml.cpp:1158
TiXmlComment()
Constructs an empty comment.
Definition tinyxml.h:1333
void CopyTo(TiXmlComment *target) const
Definition tinyxml.cpp:1168
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition tinyxml.cpp:1172
In correct XML the declaration is the first entry in the file.
Definition tinyxml.h:1469
void operator=(const TiXmlDeclaration &copy)
Definition tinyxml.cpp:1248
void CopyTo(TiXmlDeclaration *target) const
Definition tinyxml.cpp:1293
TIXML_STRING encoding
Definition tinyxml.h:1530
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
Definition tinyxml.cpp:1305
TIXML_STRING standalone
Definition tinyxml.h:1531
TiXmlDeclaration()
Construct an empty declaration.
Definition tinyxml.h:1472
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition tinyxml.cpp:1301
TIXML_STRING version
Definition tinyxml.h:1529
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
Definition tinyxml.cpp:1253
Always the top level node.
Definition tinyxml.h:1655
TIXML_STRING errorDesc
Definition tinyxml.h:1852
bool Error() const
If an error occurs, Error will be set to true.
Definition tinyxml.h:1740
virtual TiXmlNode * Clone() const
Create an exact duplicate of this node and return it.
Definition tinyxml.cpp:1015
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
Definition tinyxml.cpp:804
bool useMicrosoftBOM
Definition tinyxml.h:1855
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given null terminated block of xml data.
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
Definition tinyxml.cpp:1033
TiXmlDocument()
Create an empty document, that has no name.
Definition tinyxml.cpp:769
TiXmlCursor errorLocation
Definition tinyxml.h:1854
void Print() const
Write the document to standard out using formatted printing ("prettyprint").
Definition tinyxml.h:1810
void CopyTo(TiXmlDocument *target) const
Definition tinyxml.cpp:998
void operator=(const TiXmlDocument &copy)
Definition tinyxml.cpp:799
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition tinyxml.cpp:811
void ClearError()
If you have handled the error, it can be reset with this call.
Definition tinyxml.h:1799
The element is a container class.
Definition tinyxml.h:1095
TiXmlElement(const char *in_value)
Construct an element.
Definition tinyxml.cpp:434
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition tinyxml.cpp:736
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
Definition tinyxml.cpp:605
void ClearThis()
Definition tinyxml.cpp:461
void RemoveAttribute(const char *name)
Deletes an attribute with the given name.
Definition tinyxml.cpp:370
TiXmlAttributeSet attributeSet
Definition tinyxml.h:1325
int QueryIntAttribute(const char *name, int *_value) const
QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer...
Definition tinyxml.cpp:550
const char * Attribute(const char *name) const
Given an attribute name, Attribute() returns the value for the attribute of that name,...
Definition tinyxml.cpp:471
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
Definition tinyxml.cpp:746
virtual ~TiXmlElement()
Definition tinyxml.cpp:459
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition tinyxml.cpp:666
void CopyTo(TiXmlElement *target) const
Definition tinyxml.cpp:716
void SetAttribute(const char *name, const char *_value)
Sets an attribute of name to a given value.
Definition tinyxml.cpp:615
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
Definition tinyxml.cpp:568
const char * GetText() const
Convenience function for easy access to the text inside an element.
Definition tinyxml.cpp:755
void operator=(const TiXmlElement &base)
Definition tinyxml.cpp:454
TiXmlHandle Child(const char *value, int index) const
Return a handle to the "index" child with the given name.
Definition tinyxml.cpp:1590
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition tinyxml.h:1956
TiXmlNode * node
Definition tinyxml.h:2047
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
Definition tinyxml.cpp:1555
TiXmlHandle FirstChild() const
Return a handle to the first child node.
Definition tinyxml.cpp:1535
TiXmlHandle ChildElement(const char *value, int index) const
Return a handle to the "index" child element with the given name.
Definition tinyxml.cpp:1620
The parent class for everything in the Document Object Model.
Definition tinyxml.h:454
virtual ~TiXmlNode()
Definition tinyxml.cpp:123
int Type() const
Query the type (as an enumerated value, above) of this node.
Definition tinyxml.h:770
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition tinyxml.cpp:384
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition tinyxml.h:695
friend class TiXmlDocument
Definition tinyxml.h:455
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
Definition tinyxml.cpp:153
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
Definition tinyxml.h:800
NodeType type
Definition tinyxml.h:893
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
Definition tinyxml.cpp:231
void SetValue(const char *_value)
Changes the value of the node.
Definition tinyxml.h:538
TiXmlNode * next
Definition tinyxml.h:901
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
Definition tinyxml.h:678
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
Definition tinyxml.h:517
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition tinyxml.h:704
TiXmlNode(NodeType _type)
Definition tinyxml.cpp:113
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
Definition tinyxml.cpp:265
TiXmlNode * lastChild
Definition tinyxml.h:896
TiXmlNode * parent
Definition tinyxml.h:892
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
Definition tinyxml.cpp:331
void Clear()
Delete all the children of this node. Does not affect 'this'.
Definition tinyxml.cpp:139
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
Definition tinyxml.cpp:197
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
Definition tinyxml.h:784
NodeType
The types of XML nodes supported by TinyXml.
Definition tinyxml.h:492
@ STYLESHEETREFERENCE
Definition tinyxml.h:499
@ DECLARATION
Definition tinyxml.h:498
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
const TiXmlNode * LastChild() const
Definition tinyxml.h:572
TiXmlNode * prev
Definition tinyxml.h:900
void CopyTo(TiXmlNode *target) const
Definition tinyxml.cpp:134
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
friend class TiXmlElement
Definition tinyxml.h:456
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
Definition tinyxml.cpp:404
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
Definition tinyxml.h:788
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
Definition tinyxml.cpp:424
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
Definition tinyxml.cpp:291
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition tinyxml.h:552
TIXML_STRING value
Definition tinyxml.h:898
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
Definition tinyxml.cpp:181
const TIXML_STRING & ValueTStr() const
Definition tinyxml.h:527
TiXmlNode * firstChild
Definition tinyxml.h:895
Print to memory functionality.
Definition tinyxml.h:2070
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
Definition tinyxml.cpp:1638
void DoLineBreak()
Definition tinyxml.h:2131
bool simpleTextPrint
Definition tinyxml.h:2134
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
Definition tinyxml.cpp:1636
void DoIndent()
Definition tinyxml.h:2127
void SetStreamPrinting()
Switch over to "stream printing" which is the most dense formatting without linebreaks.
Definition tinyxml.h:2112
const std::string & Str()
Return the result.
Definition tinyxml.h:2123
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
Definition tinyxml.cpp:1715
TIXML_STRING buffer
Definition tinyxml.h:2135
A stylesheet reference looks like this:
Definition tinyxml.h:1543
void CopyTo(TiXmlStylesheetReference *target) const
Definition tinyxml.cpp:1373
TiXmlStylesheetReference()
Construct an empty declaration.
Definition tinyxml.h:1546
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition tinyxml.cpp:1380
void operator=(const TiXmlStylesheetReference &copy)
Definition tinyxml.cpp:1336
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
Definition tinyxml.cpp:1341
virtual TiXmlNode * Clone() const
Creates a copy of this StylesheetReference and returns it.
Definition tinyxml.cpp:1384
XML text.
Definition tinyxml.h:1386
bool cdata
Definition tinyxml.h:1452
void CopyTo(TiXmlText *target) const
Definition tinyxml.cpp:1204
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition tinyxml.cpp:1185
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
Definition tinyxml.cpp:1213
bool CDATA() const
Queries whether this represents text using a CDATA section.
Definition tinyxml.h:1420
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
Definition tinyxml.cpp:1209
TiXmlText(const char *initValue)
Constructor for text element.
Definition tinyxml.h:1394
Any tag that tinyXml doesn't recognize is saved as an unknown.
Definition tinyxml.h:1608
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
Definition tinyxml.cpp:1408
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition tinyxml.cpp:1393
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
Definition tinyxml.cpp:1404
void CopyTo(TiXmlUnknown *target) const
Definition tinyxml.cpp:1400
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks.
Definition tinyxml.h:144
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
Definition tinyxml.h:149
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
Definition tinyxml.h:151
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
Definition tinyxml.h:162
FILE * TiXmlFOpen(const char *filename, const char *mode)
Definition tinyxml.cpp:37
std::istream & operator>>(std::istream &in, TiXmlNode &base)
Definition tinyxml.cpp:1505
std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)
Definition tinyxml.cpp:1516
TiXmlEncoding
Definition tinyxml.h:179
@ TIXML_ENCODING_UNKNOWN
Definition tinyxml.h:180
#define TIXML_STRING
Definition tinyxml.h:60
@ TIXML_WRONG_TYPE
Definition tinyxml.h:176
@ TIXML_SUCCESS
Definition tinyxml.h:176
@ TIXML_NO_ATTRIBUTE
Definition tinyxml.h:176
#define TIXML_SSCANF
Definition tinyxml.h:91
const TiXmlEncoding TIXML_DEFAULT_ENCODING
Definition tinyxml.h:185
const unsigned char TIXML_UTF_LEAD_0
const unsigned char TIXML_UTF_LEAD_1
const unsigned char TIXML_UTF_LEAD_2