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