aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
tinyxml.cpp
Go to the documentation of this file.
1 /*
2 www.sourceforge.net/projects/tinyxml
3 Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason
4 (www.grinninglizard.com)
5 
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any
8 damages arising from the use of this software.
9 
10 Permission is granted to anyone to use this software for any
11 purpose, including commercial applications, and to alter it and
12 redistribute it freely, subject to the following restrictions:
13 
14 1. The origin of this software must not be misrepresented; you must
15 not claim that you wrote the original software. If you use this
16 software in a product, an acknowledgment in the product documentation
17 would be appreciated but is not required.
18 
19 2. Altered source versions must be plainly marked as such, and
20 must not be misrepresented as being the original software.
21 
22 3. This notice may not be removed or altered from any source
23 distribution.
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 
34 bool TiXmlBase::condenseWhiteSpace = true;
35 
36 // Microsoft compiler security
37 FILE* 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 
50 void TiXmlBase::EncodeString(const TIXML_STRING& str, TIXML_STRING* outString) {
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  sprintf(buf, "&#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 
134 void TiXmlNode::CopyTo(TiXmlNode* target) const {
135  target->SetValue(value.c_str());
136  target->userData = userData;
137 }
138 
139 void TiXmlNode::Clear() {
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())
161  GetDocument()->SetError(
162  TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN);
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())
184  GetDocument()->SetError(
185  TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN);
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())
205  GetDocument()->SetError(
206  TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN);
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())
239  GetDocument()->SetError(
240  TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN);
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 
291 bool TiXmlNode::RemoveChild(TiXmlNode* removeThis) {
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 
311 const 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 
321 const 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 
331 const 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 
340 const TiXmlNode* TiXmlNode::IterateChildren(const char* val,
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 
350 const 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 
360 const 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 
370 void 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 
394 const 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 
414 const 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 
434 TiXmlElement::TiXmlElement(const char* _value)
436  firstChild = lastChild = 0;
437  value = _value;
438 }
439 
440 #ifdef TIXML_USE_STL
441 TiXmlElement::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 
454 void TiXmlElement::operator=(const TiXmlElement& base) {
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 
471 const 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
480 const 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 
489 const 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
504 const 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 
519 const 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
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 
550 int 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
559 int 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 
568 int 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
577 int 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 
587 void 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  sprintf(buf, "%d", val);
593 #endif
594  SetAttribute(name, buf);
595 }
596 
597 #ifdef TIXML_USE_STL
598 void TiXmlElement::SetAttribute(const std::string& name, int val) {
599  std::ostringstream oss;
600  oss << val;
601  SetAttribute(name, oss.str());
602 }
603 #endif
604 
605 void 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  sprintf(buf, "%f", val);
611 #endif
612  SetAttribute(name, buf);
613 }
614 
615 void 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
644 void 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 
666 void 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 
716 void TiXmlElement::CopyTo(TiXmlElement* target) const {
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 
736 bool 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 
755 const 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 
771  tabsize = 4;
772  useMicrosoftBOM = false;
773  ClearError();
774 }
775 
776 TiXmlDocument::TiXmlDocument(const char* documentName)
778  tabsize = 4;
779  useMicrosoftBOM = false;
780  value = documentName;
781  ClearError();
782 }
783 
784 #ifdef TIXML_USE_STL
785 TiXmlDocument::TiXmlDocument(const std::string& documentName)
787  tabsize = 4;
788  useMicrosoftBOM = false;
789  value = documentName;
790  ClearError();
791 }
792 #endif
793 
796  copy.CopyTo(this);
797 }
798 
799 void TiXmlDocument::operator=(const TiXmlDocument& copy) {
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 
811 bool TiXmlDocument::SaveFile() const {
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 
822 bool 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 
846 bool TiXmlDocument::LoadFile(FILE* file, TiXmlEncoding encoding) {
847  if (!file) {
849  return false;
850  }
851 
852  // Delete the existing data:
853  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 
970 bool 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 
983 bool 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 
998 void TiXmlDocument::CopyTo(TiXmlDocument* target) const {
999  TiXmlNode::CopyTo(target);
1000 
1001  target->error = error;
1002  target->errorId = errorId;
1003  target->errorDesc = errorDesc;
1004  target->tabsize = tabsize;
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 
1024 void 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 
1033 bool TiXmlDocument::Accept(TiXmlVisitor* visitor) const {
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 /*
1052 TiXmlAttribute* 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 /*
1071 TiXmlAttribute* 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 
1081 void 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 
1112 int 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 
1118 int 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 
1124 void TiXmlAttribute::SetIntValue(int _value) {
1125  char buf[64];
1126 #if defined(TIXML_SNPRINTF)
1127  TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
1128 #else
1129  sprintf(buf, "%d", _value);
1130 #endif
1131  SetValue(buf);
1132 }
1133 
1134 void TiXmlAttribute::SetDoubleValue(double _value) {
1135  char buf[256];
1136 #if defined(TIXML_SNPRINTF)
1137  TIXML_SNPRINTF(buf, sizeof(buf), "%g", _value);
1138 #else
1139  sprintf(buf, "%lf", _value);
1140 #endif
1141  SetValue(buf);
1142 }
1143 
1144 int TiXmlAttribute::IntValue() const { return atoi(value.c_str()); }
1145 
1146 double TiXmlAttribute::DoubleValue() const { return atof(value.c_str()); }
1147 
1150  copy.CopyTo(this);
1151 }
1152 
1153 void TiXmlComment::operator=(const TiXmlComment& base) {
1154  Clear();
1155  base.CopyTo(this);
1156 }
1157 
1158 void 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 
1168 void TiXmlComment::CopyTo(TiXmlComment* target) const {
1169  TiXmlNode::CopyTo(target);
1170 }
1171 
1172 bool TiXmlComment::Accept(TiXmlVisitor* visitor) const {
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 
1185 void 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 
1204 void TiXmlText::CopyTo(TiXmlText* target) const {
1205  TiXmlNode::CopyTo(target);
1206  target->cdata = cdata;
1207 }
1208 
1209 bool 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 
1223 TiXmlDeclaration::TiXmlDeclaration(const char* _version,
1224  const char* _encoding,
1225  const char* _standalone)
1227  version = _version;
1228  encoding = _encoding;
1229  standalone = _standalone;
1230 }
1231 
1232 #ifdef TIXML_USE_STL
1233 TiXmlDeclaration::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 
1245  copy.CopyTo(this);
1246 }
1247 
1249  Clear();
1250  copy.CopyTo(this);
1251 }
1252 
1253 void 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 
1301 bool TiXmlDeclaration::Accept(TiXmlVisitor* visitor) const {
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 
1331  const TiXmlStylesheetReference& copy)
1333  copy.CopyTo(this);
1334 }
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 
1393 void 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 
1400 void TiXmlUnknown::CopyTo(TiXmlUnknown* target) const {
1401  TiXmlNode::CopyTo(target);
1402 }
1403 
1404 bool TiXmlUnknown::Accept(TiXmlVisitor* visitor) const {
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 
1418  sentinel.next = &sentinel;
1419  sentinel.prev = &sentinel;
1420 }
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
1459 const 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 /*
1469 TiXmlAttribute* TiXmlAttributeSet::Find( const std::string& name )
1470 {
1471  for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node =
1472 node->next )
1473  {
1474  if ( node->name == name )
1475  return node;
1476  }
1477  return 0;
1478 }
1479 */
1480 #endif
1481 
1482 const 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 /*
1492 TiXmlAttribute* TiXmlAttributeSet::Find( const char* name )
1493 {
1494  for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node =
1495 node->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
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
1517  TiXmlPrinter printer;
1518  printer.SetStreamPrinting();
1519  base.Accept(&printer);
1520  out << printer.Str();
1521 
1522  return out;
1523 }
1524 
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 
1545 TiXmlHandle 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) {
1558 
1559  if (child) return TiXmlHandle(child);
1560  }
1561 
1562  return TiXmlHandle(0);
1563 }
1564 
1565 TiXmlHandle TiXmlHandle::FirstChildElement(const char* value) const {
1566  if (node) {
1568 
1569  if (child) return TiXmlHandle(child);
1570  }
1571 
1572  return TiXmlHandle(0);
1573 }
1574 
1575 TiXmlHandle TiXmlHandle::Child(int count) const {
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 
1590 TiXmlHandle 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;
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 
1620 TiXmlHandle TiXmlHandle::ChildElement(const char* value, int count) const {
1621  if (node) {
1622  int i;
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 
1636 bool TiXmlPrinter::VisitEnter(const TiXmlDocument&) { return true; }
1637 
1638 bool TiXmlPrinter::VisitExit(const TiXmlDocument&) { return true; }
1639 
1640 bool TiXmlPrinter::VisitEnter(const TiXmlElement& element,
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 
1672 bool TiXmlPrinter::VisitExit(const TiXmlElement& element) {
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 
1693 bool TiXmlPrinter::Visit(const TiXmlText& text) {
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 
1715 bool TiXmlPrinter::Visit(const TiXmlDeclaration& declaration) {
1716  DoIndent();
1717  declaration.Print(0, 0, &buffer);
1718  DoLineBreak();
1719  return true;
1720 }
1721 
1722 bool TiXmlPrinter::Visit(const TiXmlComment& comment) {
1723  DoIndent();
1724  buffer += "<!--";
1725  buffer += comment.Value();
1726  buffer += "-->";
1727  DoLineBreak();
1728  return true;
1729 }
1730 
1731 bool TiXmlPrinter::Visit(const TiXmlUnknown& unknown) {
1732  DoIndent();
1733  buffer += "<";
1734  buffer += unknown.Value();
1735  buffer += ">";
1736  DoLineBreak();
1737  return true;
1738 }
1739 
1740 bool TiXmlPrinter::Visit(const TiXmlStylesheetReference& stylesheet) {
1741  DoIndent();
1742  stylesheet.Print(0, 0, &buffer);
1743  DoLineBreak();
1744  return true;
1745 }
TiXmlStylesheetReference(const std::string &_type, const std::string &_href)
Constructor.
Definition: tinyxml.cpp:1322
int QueryIntValue(int *_value) const
QueryIntValue examines the value string.
Definition: tinyxml.cpp:1112
TiXmlNode * FirstChild(const char *_value)
Definition: tinyxml.h:564
virtual bool VisitExit(const TiXmlElement &element)
Visit an element.
Definition: tinyxml.cpp:1672
void DoLineBreak()
Definition: tinyxml.h:2131
bool SaveFile(FILE *) const
Save a file using the given FILE*. Returns true if successful.
Definition: tinyxml.cpp:983
An attribute is a name-value pair.
Definition: tinyxml.h:915
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
void Print(FILE *cfile, int depth, TIXML_STRING *str) const
Definition: tinyxml.cpp:1081
virtual ~TiXmlElement()
Definition: tinyxml.cpp:459
TiXmlDocument(const char *documentName)
Create a document with a name. The name of the document is also the filename of the xml...
Definition: tinyxml.cpp:776
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks...
Definition: tinyxml.h:144
TiXmlDeclaration(const std::string &_version, const std::string &_encoding, const std::string &_standalone)
Constructor.
Definition: tinyxml.cpp:1233
FILE * TiXmlFOpen(const char *filename, const char *mode)
Definition: tinyxml.cpp:37
TiXmlDeclaration(const TiXmlDeclaration &copy)
Definition: tinyxml.cpp:1243
TiXmlComment()
Constructs an empty comment.
Definition: tinyxml.h:1333
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 bool Visit(const TiXmlUnknown &)
Visit an unknow node.
Definition: tinyxml.h:172
void SetAttribute(const std::string &name, const std::string &_value)
STL std::string form.
Definition: tinyxml.cpp:644
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
Definition: tinyxml.h:937
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:944
TiXmlNode * prev
Definition: tinyxml.h:900
const TiXmlNode * PreviousSibling(const char *) const
Navigate to a sibling node.
Definition: tinyxml.cpp:360
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
Definition: tinyxml.cpp:1341
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.cpp:568
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
Definition: tinyxml.cpp:1118
TiXmlNode * firstChild
Definition: tinyxml.h:895
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
Definition: tinyxml.cpp:605
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:788
void CopyTo(TiXmlDocument *target) const
Definition: tinyxml.cpp:998
std::string & operator<<(std::string &out, const TiXmlNode &base)
Definition: tinyxml.cpp:1525
TiXmlHandle ChildElement(const char *value, int index) const
Return a handle to the "index" child element with the given name.
Definition: tinyxml.cpp:1620
virtual void Print(FILE *cfile, int depth=0) const
Print this Document to a FILE stream.
Definition: tinyxml.cpp:1024
const char * GetText() const
Convenience function for easy access to the text inside an element.
Definition: tinyxml.cpp:755
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1033
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:800
bool Error() const
If an error occurs, Error will be set to true.
Definition: tinyxml.h:1740
void operator=(const TiXmlDeclaration &copy)
Definition: tinyxml.cpp:1248
TiXmlElement * FirstChildElement(const char *_value)
Definition: tinyxml.h:752
void operator=(const TiXmlDocument &copy)
Definition: tinyxml.cpp:799
TiXmlHandle FirstChildElement(const char *value) const
Return a handle to the first child element with the given name.
Definition: tinyxml.cpp:1565
void ClearThis()
Definition: tinyxml.cpp:461
TiXmlHandle Child(int index) const
Return a handle to the "index" child.
Definition: tinyxml.cpp:1575
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
Definition: tinyxml.cpp:1408
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
Definition: tinyxml.cpp:265
virtual bool VisitExit(const TiXmlElement &)
Visit an element.
Definition: tinyxml.h:159
bool CDATA() const
Queries whether this represents text using a CDATA section.
Definition: tinyxml.h:1420
TiXmlNode * NextSibling()
Definition: tinyxml.h:705
TiXmlDocument()
Create an empty document, that has no name.
Definition: tinyxml.cpp:769
void DoIndent()
Definition: tinyxml.h:2127
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1301
void CopyTo(TiXmlElement *target) const
Definition: tinyxml.cpp:716
TiXmlElement * FirstChildElement()
Definition: tinyxml.h:745
void ClearError()
If you have handled the error, it can be reset with this call.
Definition: tinyxml.h:1799
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
void SetAttribute(const char *name, int value)
Sets an attribute of name to a given value.
Definition: tinyxml.cpp:587
void Clear()
Definition: tinyxml.h:114
void CopyTo(TiXmlUnknown *target) const
Definition: tinyxml.cpp:1400
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
TiXmlDocument(const TiXmlDocument &copy)
Definition: tinyxml.cpp:794
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
Definition: tinyxml.cpp:804
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cpp:181
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
Definition: tinyxml.cpp:1638
const TiXmlNode * NextSibling(const char *) const
Navigate to a sibling node with the given &#39;value&#39;.
Definition: tinyxml.cpp:350
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cpp:197
void CopyTo(TiXmlDeclaration *target) const
Definition: tinyxml.cpp:1293
static bool condenseWhiteSpace
Definition: tinyxml.h:445
bool LoadFile(const char *filename, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the given filename. Returns true if successful.
Definition: tinyxml.cpp:822
const TiXmlElement * NextSiblingElement(const char *) const
Convenience function to get through elements.
Definition: tinyxml.cpp:414
NodeType
The types of XML nodes supported by TinyXml.
Definition: tinyxml.h:492
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
Definition: tinyxml.cpp:153
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition: tinyxml.cpp:811
void operator=(const TiXmlComment &base)
Definition: tinyxml.cpp:1153
TiXmlHandle Child(const char *value, int index) const
Return a handle to the "index" child with the given name.
Definition: tinyxml.cpp:1590
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cpp:384
void SetDoubleValue(double _value)
Set the value from a double.
Definition: tinyxml.cpp:1134
void * userData
Field containing a generic user pointer.
Definition: tinyxml.h:413
A stylesheet reference looks like this:
Definition: tinyxml.h:1543
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
TiXmlAttribute * prev
Definition: tinyxml.h:1030
virtual TiXmlNode * Clone() const
Returns a copy of this Comment.
Definition: tinyxml.cpp:1176
const TiXmlNode * IterateChildren(const char *value, const TiXmlNode *previous) const
This flavor of IterateChildren searches for children with a particular &#39;value&#39;.
Definition: tinyxml.cpp:340
In correct XML the declaration is the first entry in the file.
Definition: tinyxml.h:1469
bool cdata
Definition: tinyxml.h:1452
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:947
std::istream & operator>>(std::istream &in, TiXmlNode &base)
Definition: tinyxml.cpp:1505
Any tag that tinyXml doesn&#39;t recognize is saved as an unknown.
Definition: tinyxml.h:1608
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
virtual bool Visit(const TiXmlText &)
Visit a text node.
Definition: tinyxml.h:168
int IntValue() const
Return the value of this attribute, converted to an integer.
Definition: tinyxml.cpp:1144
TiXmlNode * NextSibling(const char *_next)
Definition: tinyxml.h:709
TiXmlNode * FirstChild()
Definition: tinyxml.h:555
TiXmlStylesheetReference()
Construct an empty declaration.
Definition: tinyxml.h:1546
TiXmlAttribute * next
Definition: tinyxml.h:1031
void CopyTo(TiXmlStylesheetReference *target) const
Definition: tinyxml.cpp:1373
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
Definition: tinyxml.cpp:1305
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
Definition: tinyxml.cpp:1213
TiXmlCursor location
Definition: tinyxml.h:410
const char * Value() const
The meaning of &#39;value&#39; changes for the specific type of TiXmlNode.
Definition: tinyxml.h:517
void CopyTo(TiXmlComment *target) const
Definition: tinyxml.cpp:1168
void CopyTo(TiXmlText *target) const
Definition: tinyxml.cpp:1204
const TiXmlAttribute * Find(const std::string &_name) const
Definition: tinyxml.cpp:1459
void RemoveAttribute(const char *name)
Deletes an attribute with the given name.
Definition: tinyxml.cpp:370
void SetAttribute(const char *name, const char *_value)
Sets an attribute of name to a given value.
Definition: tinyxml.cpp:615
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
double DoubleValue() const
Return the value of this attribute, converted to a double.
Definition: tinyxml.cpp:1146
virtual bool Visit(const TiXmlStylesheetReference &)
Visit a stylesheet reference.
Definition: tinyxml.h:164
friend class TiXmlElement
Definition: tinyxml.h:1387
virtual bool VisitEnter(const TiXmlElement &element, const TiXmlAttribute *firstAttribute)
Visit an element.
Definition: tinyxml.cpp:1640
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
Definition: tinyxml.cpp:404
Always the top level node.
Definition: tinyxml.h:1655
TiXmlHandle FirstChild() const
Return a handle to the first child node.
Definition: tinyxml.cpp:1535
TiXmlEncoding
Definition: tinyxml.h:179
TiXmlElement(const char *in_value)
Construct an element.
Definition: tinyxml.cpp:434
const std::string * Attribute(const std::string &name, int *i) const
Definition: tinyxml.cpp:504
const char * Attribute(const char *name, double *d) const
Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
Definition: tinyxml.cpp:519
void operator=(const TiXmlStylesheetReference &copy)
Definition: tinyxml.cpp:1336
virtual bool Visit(const TiXmlText &text)
Visit a text node.
Definition: tinyxml.cpp:1693
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cpp:231
TiXmlHandle FirstChild(const char *value) const
Return a handle to the first child node with the given name.
Definition: tinyxml.cpp:1545
void CopyTo(TiXmlNode *target) const
Definition: tinyxml.cpp:134
void Add(TiXmlAttribute *attribute)
Definition: tinyxml.cpp:1427
TiXmlNode * node
Definition: tinyxml.h:2047
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
Definition: tinyxml.h:1951
virtual bool Visit(const TiXmlUnknown &unknown)
Visit an unknow node.
Definition: tinyxml.cpp:1731
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Definition: tinyxml.cpp:1043
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
Definition: tinyxml.cpp:424
bool LoadFile(FILE *, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the given FILE*.
Definition: tinyxml.cpp:846
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1380
const TiXmlAttribute * Find(const char *_name) const
Definition: tinyxml.cpp:1482
TiXmlStylesheetReference(const TiXmlStylesheetReference &copy)
Definition: tinyxml.cpp:1330
TiXmlBase is a base class for every class in TinyXml.
Definition: tinyxml.h:211
int Type() const
Query the type (as an enumerated value, above) of this node.
Definition: tinyxml.h:770
int QueryIntAttribute(const std::string &name, int *_value) const
Definition: tinyxml.cpp:559
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:552
const char * Attribute(const char *name, int *i) const
Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
Definition: tinyxml.cpp:489
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
Definition: tinyxml.cpp:1636
void operator=(const TiXmlElement &base)
Definition: tinyxml.cpp:454
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
Definition: tinyxml.cpp:746
TiXmlNode * parent
Definition: tinyxml.h:892
#define TIXML_USE_STL
Definition: tinyxml.h:52
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1172
TiXmlDocument(const std::string &documentName)
Constructor.
Definition: tinyxml.cpp:785
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
TiXmlNode(NodeType _type)
Definition: tinyxml.cpp:113
TiXmlHandle ChildElement(int index) const
Return a handle to the "index" child element.
Definition: tinyxml.cpp:1605
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:454
TiXmlComment(const TiXmlComment &)
Definition: tinyxml.cpp:1148
void SetIntValue(int _value)
Set the value from an integer.
Definition: tinyxml.cpp:1124
Print to memory functionality.
Definition: tinyxml.h:2070
virtual TiXmlNode * Clone() const
Creates a copy of this StylesheetReference and returns it.
Definition: tinyxml.cpp:1384
TiXmlNode * next
Definition: tinyxml.h:901
const std::string * Attribute(const std::string &name, double *d) const
Definition: tinyxml.cpp:534
TiXmlElement(const std::string &_value)
std::string constructor.
Definition: tinyxml.cpp:441
#define TIXML_SSCANF
Definition: tinyxml.h:91
virtual bool Visit(const TiXmlComment &)
Visit a comment node.
Definition: tinyxml.h:170
const TiXmlNode * FirstChild(const char *value) const
The first child of this node with the matching &#39;value&#39;. Will be null if none found. The first child of this node with the matching &#39;value&#39;. Will be null if none found.
Definition: tinyxml.cpp:311
virtual TiXmlNode * Clone() const
Create an exact duplicate of this node and return it.
Definition: tinyxml.cpp:1015
const std::string * Attribute(const std::string &name) const
Definition: tinyxml.cpp:480
const char * Attribute(const char *name) const
Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
Definition: tinyxml.cpp:471
virtual bool Visit(const TiXmlComment &comment)
Visit a comment node.
Definition: tinyxml.cpp:1722
TiXmlText(const char *initValue)
Constructor for text element.
Definition: tinyxml.h:1394
bool useMicrosoftBOM
Definition: tinyxml.h:1855
TiXmlDeclaration(const char *_version, const char *_encoding, const char *_standalone)
Construct.
Definition: tinyxml.cpp:1223
const TiXmlElement * FirstChildElement(const char *_value) const
Convenience function to get through elements.
Definition: tinyxml.cpp:394
NodeType type
Definition: tinyxml.h:893
int QueryDoubleAttribute(const std::string &name, double *_value) const
Definition: tinyxml.cpp:577
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
Definition: tinyxml.cpp:291
bool SaveFile(const char *filename) const
Save a file using the given filename. Returns true if successful.
Definition: tinyxml.cpp:970
TiXmlStylesheetReference(const char *_type, const char *_href)
Construct.
Definition: tinyxml.cpp:1314
An XML comment.
Definition: tinyxml.h:1330
const TiXmlNode * LastChild(const char *value) const
Definition: tinyxml.cpp:321
void Remove(TiXmlAttribute *attribute)
Definition: tinyxml.cpp:1442
void Clear()
Delete all the children of this node. Does not affect &#39;this&#39;.
Definition: tinyxml.cpp:139
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:979
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
Definition: tinyxml.cpp:1062
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
Definition: tinyxml.cpp:331
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1209
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:736
TiXmlNode * lastChild
Definition: tinyxml.h:896
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
Definition: tinyxml.cpp:1555
TiXmlDeclaration()
Construct an empty declaration.
Definition: tinyxml.h:1472
void SetStreamPrinting()
Switch over to "stream printing" which is the most dense formatting without linebreaks.
Definition: tinyxml.h:2112
virtual ~TiXmlNode()
Definition: tinyxml.cpp:123
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
Definition: tinyxml.cpp:1253
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:704
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
Definition: tinyxml.cpp:1715
TiXmlElement(const TiXmlElement &)
Definition: tinyxml.cpp:448
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:829
#define TIXML_STRING
Definition: tinyxml.h:60
The element is a container class.
Definition: tinyxml.h:1095
void SetAttribute(const std::string &name, int _value)
Definition: tinyxml.cpp:598
bool simpleTextPrint
Definition: tinyxml.h:2134
TiXmlCursor errorLocation
Definition: tinyxml.h:1854
virtual bool Visit(const TiXmlStylesheetReference &stylesheet)
Visit a stylesheet reference.
Definition: tinyxml.cpp:1740
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1404
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
TiXmlBase()
Definition: tinyxml.h:221
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
Definition: tinyxml.h:162