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