ddc
tinyxml.h
Go to the documentation of this file.
1 /*
2 www.sourceforge.net/projects/tinyxml
3 Original code (2.0 and earlier )copyright (c) 2000-2002 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 
26 #ifndef TINYXML_INCLUDED
27 #define TINYXML_INCLUDED
28 
29 #ifdef _MSC_VER
30 #pragma warning( disable : 4530 )
31 #pragma warning( disable : 4786 )
32 #pragma warning( disable : 4996 )
33 #endif
34 
35 //-- suppress irritating warnings from clang (moocow, Fri, 14 Feb 2020 12:55:42 +0100)
36 #ifdef __clang__
37 #pragma clang diagnostic push
38 #pragma clang diagnostic ignored "-Wundefined-bool-conversion"
39 #endif
40 
41 #include <ctype.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <assert.h>
46 
47 // Help out windows:
48 #if defined( _DEBUG ) && !defined( DEBUG )
49 #define DEBUG
50 #endif
51 
52 #if defined( DEBUG ) && defined( _MSC_VER )
53 #include <windows.h>
54 #define TIXML_LOG OutputDebugString
55 #else
56 #define TIXML_LOG printf
57 #endif
58 
59 #ifdef TIXML_USE_STL
60  #include <string>
61  #include <iostream>
62  #define TIXML_STRING std::string
63  #define TIXML_ISTREAM std::istream
64  #define TIXML_OSTREAM std::ostream
65 #else
66  #include "tinystr.h"
67  #define TIXML_STRING TiXmlString
68  #define TIXML_OSTREAM TiXmlOutStream
69 #endif
70 
71 class TiXmlDocument;
72 class TiXmlElement;
73 class TiXmlComment;
74 class TiXmlUnknown;
75 class TiXmlAttribute;
76 class TiXmlText;
77 class TiXmlDeclaration;
78 class TiXmlParsingData;
79 
80 const int TIXML_MAJOR_VERSION = 2;
81 const int TIXML_MINOR_VERSION = 3;
82 const int TIXML_PATCH_VERSION = 1;
83 
84 /* Internal structure for tracking location of items
85  in the XML file.
86 */
88 {
89  TiXmlCursor() { Clear(); }
90  void Clear() { row = col = -1; }
91 
92  int row; // 0 based.
93  int col; // 0 based.
94 };
95 
96 
97 // Only used by Attribute::Query functions
98 enum
99 {
103 };
104 
105 
106 // Used by the parsing routines.
108 {
112 };
113 
115 
139 {
140  friend class TiXmlNode;
141  friend class TiXmlElement;
142  friend class TiXmlDocument;
143 
144 public:
145  TiXmlBase() : userData(0) {}
146  virtual ~TiXmlBase() {}
147 
153  virtual void Print( FILE* cfile, int depth ) const = 0;
154 
161  static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
162 
164  static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
165 
184  int Row() const { return location.row + 1; }
185  int Column() const { return location.col + 1; }
186 
187  void SetUserData( void* user ) { userData = user; }
188  void* GetUserData() { return userData; }
189 
190  // Table that returs, for a given lead byte, the total number of bytes
191  // in the UTF-8 sequence.
192  static const int utf8ByteTable[256];
193 
194  virtual const char* Parse( const char* p,
195  TiXmlParsingData* data,
196  TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
197 
198 protected:
199 
200  // See STL_STRING_BUG
201  // Utility class to overcome a bug.
203  {
204  public:
205  StringToBuffer( const TIXML_STRING& str );
206  ~StringToBuffer();
207  char* buffer;
208  };
209 
210  static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
211  inline static bool IsWhiteSpace( char c )
212  {
213  return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
214  }
215 
216  virtual void StreamOut (TIXML_OSTREAM *) const = 0;
217 
218  #ifdef TIXML_USE_STL
219  static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
220  static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
221  #endif
222 
223  /* Reads an XML name into the string provided. Returns
224  a pointer just past the last character of the name,
225  or 0 if the function has an error.
226  */
227  static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
228 
229  /* Reads text. Returns a pointer past the given end tag.
230  Wickedly complex options, but it keeps the (sensitive) code in one place.
231  */
232  static const char* ReadText( const char* in, // where to start
233  TIXML_STRING* text, // the string read
234  bool ignoreWhiteSpace, // whether to keep the white space
235  const char* endTag, // what ends this text
236  bool ignoreCase, // whether to ignore case in the end tag
237  TiXmlEncoding encoding ); // the current encoding
238 
239  // If an entity has been found, transform it into a character.
240  static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
241 
242  // Get a character, while interpreting entities.
243  // The length can be from 0 to 4 bytes.
244  inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
245  {
246  assert( p );
247  if ( encoding == TIXML_ENCODING_UTF8 )
248  {
249  *length = utf8ByteTable[ *((unsigned char*)p) ];
250  assert( *length >= 0 && *length < 5 );
251  }
252  else
253  {
254  *length = 1;
255  }
256 
257  if ( *length == 1 )
258  {
259  if ( *p == '&' )
260  return GetEntity( p, _value, length, encoding );
261  *_value = *p;
262  return p+1;
263  }
264  else if ( *length )
265  {
266  strncpy( _value, p, *length );
267  return p + (*length);
268  }
269  else
270  {
271  // Not valid text.
272  return 0;
273  }
274  }
275 
276  // Puts a string to a stream, expanding entities as it goes.
277  // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
278  static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
279 
280  static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
281 
282  // Return true if the next characters in the stream are any of the endTag sequences.
283  // Ignore case only works for english, and should only be relied on when comparing
284  // to Engilish words: StringEqual( p, "version", true ) is fine.
285  static bool StringEqual( const char* p,
286  const char* endTag,
287  bool ignoreCase,
288  TiXmlEncoding encoding );
289 
290 
291  enum
292  {
293  TIXML_NO_ERROR = 0,
308 
309  TIXML_ERROR_STRING_COUNT
310  };
311  static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
312 
314 
316  void* userData;
317 
318  // None of these methods are reliable for any language except English.
319  // Good for approximation, not great for accuracy.
320  static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
321  static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
322  inline static int ToLower( int v, TiXmlEncoding encoding )
323  {
324  if ( encoding == TIXML_ENCODING_UTF8 )
325  {
326  if ( v < 128 ) return tolower( v );
327  return v;
328  }
329  else
330  {
331  return tolower( v );
332  }
333  }
334  static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
335 
336 private:
337  TiXmlBase( const TiXmlBase& ); // not implemented.
338  void operator=( const TiXmlBase& base ); // not allowed.
339 
340  struct Entity
341  {
342  const char* str;
343  unsigned int strLength;
344  char chr;
345  };
346  enum
347  {
348  TINYXML_NUM_ENTITY = 5,
349  MAX_ENTITY_LENGTH = 6
350 
351  };
352  static Entity entity[ TINYXML_NUM_ENTITY ];
353  static bool condenseWhiteSpace;
354 };
355 
356 
363 class TiXmlNode : public TiXmlBase
364 {
365  friend class TiXmlDocument;
366  friend class TiXmlElement;
367 
368 public:
369  #ifdef TIXML_USE_STL
370 
374  friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
375 
392  friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
393 
395  friend std::string& operator<< (std::string& out, const TiXmlNode& base );
396 
397  #else
398  // Used internally, not part of the public API.
399  friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
400  #endif
401 
405  enum NodeType
406  {
414  };
415 
416  virtual ~TiXmlNode();
417 
430  const char * Value() const { return value.c_str (); }
431 
441  void SetValue(const char * _value) { value = _value;}
442 
443  #ifdef TIXML_USE_STL
444  void SetValue( const std::string& _value )
446  {
447  StringToBuffer buf( _value );
448  SetValue( buf.buffer ? buf.buffer : "" );
449  }
450  #endif
451 
453  void Clear();
454 
456  TiXmlNode* Parent() const { return parent; }
457 
458  TiXmlNode* FirstChild() const { return firstChild; }
459  TiXmlNode* FirstChild( const char * value ) const;
460 
461  TiXmlNode* LastChild() const { return lastChild; }
462  TiXmlNode* LastChild( const char * value ) const;
463 
464  #ifdef TIXML_USE_STL
465  TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
466  TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
467  #endif
468 
485  TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
486 
488  TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
489 
490  #ifdef TIXML_USE_STL
491  TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
492  #endif
493 
497  TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
498 
499 
509  TiXmlNode* LinkEndChild( TiXmlNode* addThis );
510 
514  TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
515 
519  TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
520 
524  TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
525 
527  bool RemoveChild( TiXmlNode* removeThis );
528 
530  TiXmlNode* PreviousSibling() const { return prev; }
531 
533  TiXmlNode* PreviousSibling( const char * ) const;
534 
535  #ifdef TIXML_USE_STL
536  TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
537  TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
538  #endif
539 
541  TiXmlNode* NextSibling() const { return next; }
542 
544  TiXmlNode* NextSibling( const char * ) const;
545 
551 
556  TiXmlElement* NextSiblingElement( const char * ) const;
557 
558  #ifdef TIXML_USE_STL
559  TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
560  #endif
561 
564 
566  TiXmlElement* FirstChildElement( const char * value ) const;
567 
568  #ifdef TIXML_USE_STL
569  TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
570  #endif
571 
576  virtual int Type() const { return type; }
577 
581  TiXmlDocument* GetDocument() const;
582 
584  bool NoChildren() const { return !firstChild; }
585 
586  TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
587  TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
588  TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
589  TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
590  TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
591  TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
592 
596  virtual TiXmlNode* Clone() const = 0;
597 
598 protected:
599  TiXmlNode( NodeType _type );
600 
601  // Copy to the allocated object. Shared functionality between Clone, Copy constructor,
602  // and the assignment operator.
603  void CopyTo( TiXmlNode* target ) const;
604 
605  #ifdef TIXML_USE_STL
606  // The real work of the input operator.
607  virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
608  #endif
609 
610  // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
611  TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
612 
613  // Internal Value function returning a TIXML_STRING
614  const TIXML_STRING& SValue() const { return value ; }
615 
618 
621 
623 
626 
627 private:
628  TiXmlNode( const TiXmlNode& ); // not implemented.
629  void operator=( const TiXmlNode& base ); // not allowed.
630 };
631 
632 
640 class TiXmlAttribute : public TiXmlBase
641 {
642  friend class TiXmlAttributeSet;
643 
644 public:
647  {
648  document = 0;
649  prev = next = 0;
650  }
651 
652  #ifdef TIXML_USE_STL
653  TiXmlAttribute( const std::string& _name, const std::string& _value )
655  {
656  name = _name;
657  value = _value;
658  document = 0;
659  prev = next = 0;
660  }
661  #endif
662 
664  TiXmlAttribute( const char * _name, const char * _value )
665  {
666  name = _name;
667  value = _value;
668  document = 0;
669  prev = next = 0;
670  }
671 
672  const char* Name() const { return name.c_str (); }
673  const char* Value() const { return value.c_str (); }
674  const int IntValue() const;
675  const double DoubleValue() const;
676 
686  int QueryIntValue( int* value ) const;
688  int QueryDoubleValue( double* value ) const;
689 
690  void SetName( const char* _name ) { name = _name; }
691  void SetValue( const char* _value ) { value = _value; }
692 
693  void SetIntValue( int value );
694  void SetDoubleValue( double value );
695 
696  #ifdef TIXML_USE_STL
697  void SetName( const std::string& _name )
699  {
700  StringToBuffer buf( _name );
701  SetName ( buf.buffer ? buf.buffer : "error" );
702  }
704  void SetValue( const std::string& _value )
705  {
706  StringToBuffer buf( _value );
707  SetValue( buf.buffer ? buf.buffer : "error" );
708  }
709  #endif
710 
712  TiXmlAttribute* Next() const;
714  TiXmlAttribute* Previous() const;
715 
716  bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
717  bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
718  bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
719 
720  /* Attribute parsing starts: first letter of the name
721  returns: the next char after the value end quote
722  */
723  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
724 
725  // Prints this Attribute to a FILE stream.
726  virtual void Print( FILE* cfile, int depth ) const;
727 
728  virtual void StreamOut( TIXML_OSTREAM * out ) const;
729  // [internal use]
730  // Set the document pointer so the attribute can report errors.
731  void SetDocument( TiXmlDocument* doc ) { document = doc; }
732 
733 private:
734  TiXmlAttribute( const TiXmlAttribute& ); // not implemented.
735  void operator=( const TiXmlAttribute& base ); // not allowed.
736 
737  TiXmlDocument* document; // A pointer back to a document, for error reporting.
742 };
743 
744 
745 /* A class used to manage a group of attributes.
746  It is only used internally, both by the ELEMENT and the DECLARATION.
747 
748  The set can be changed transparent to the Element and Declaration
749  classes that use it, but NOT transparent to the Attribute
750  which has to implement a next() and previous() method. Which makes
751  it a bit problematic and prevents the use of STL.
752 
753  This version is implemented with circular lists because:
754  - I like circular lists
755  - it demonstrates some independence from the (typical) doubly linked list.
756 */
758 {
759 public:
762 
763  void Add( TiXmlAttribute* attribute );
764  void Remove( TiXmlAttribute* attribute );
765 
766  TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
767  TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
768  TiXmlAttribute* Find( const char * name ) const;
769 
770 private:
772 };
773 
774 
779 class TiXmlElement : public TiXmlNode
780 {
781 public:
783  TiXmlElement (const char * in_value);
784 
785  #ifdef TIXML_USE_STL
786  TiXmlElement( const std::string& _value );
788  #endif
789 
790  TiXmlElement( const TiXmlElement& );
791 
792  void operator=( const TiXmlElement& base );
793 
794  virtual ~TiXmlElement();
795 
799  const char* Attribute( const char* name ) const;
800 
807  const char* Attribute( const char* name, int* i ) const;
808 
815  const char* Attribute( const char* name, double* d ) const;
816 
824  int QueryIntAttribute( const char* name, int* value ) const;
826  int QueryDoubleAttribute( const char* name, double* value ) const;
827 
831  void SetAttribute( const char* name, const char * value );
832 
833  #ifdef TIXML_USE_STL
834  const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
835  const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
836  const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); }
837  int QueryIntAttribute( const std::string& name, int* value ) const { return QueryIntAttribute( name.c_str(), value ); }
838  int QueryDoubleAttribute( const std::string& name, double* value ) const { return QueryDoubleAttribute( name.c_str(), value ); }
839 
841  void SetAttribute( const std::string& name, const std::string& _value )
842  {
843  StringToBuffer n( name );
844  StringToBuffer v( _value );
845  if ( n.buffer && v.buffer )
846  SetAttribute (n.buffer, v.buffer );
847  }
849  void SetAttribute( const std::string& name, int _value )
850  {
851  StringToBuffer n( name );
852  if ( n.buffer )
853  SetAttribute (n.buffer, _value);
854  }
855  #endif
856 
860  void SetAttribute( const char * name, int value );
861 
865  void SetDoubleAttribute( const char * name, double value );
866 
869  void RemoveAttribute( const char * name );
870  #ifdef TIXML_USE_STL
871  void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
872  #endif
873 
874  TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
875  TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
876 
878  virtual TiXmlNode* Clone() const;
879  // Print the Element to a FILE stream.
880  virtual void Print( FILE* cfile, int depth ) const;
881 
882  /* Attribtue parsing starts: next char past '<'
883  returns: next char past '>'
884  */
885  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
886 
887 protected:
888 
889  void CopyTo( TiXmlElement* target ) const;
890  void ClearThis(); // like clear, but initializes 'this' object as well
891 
892  // Used to be public [internal use]
893  #ifdef TIXML_USE_STL
894  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
895  #endif
896  virtual void StreamOut( TIXML_OSTREAM * out ) const;
897 
898  /* [internal use]
899  Reads the "value" of the element -- another element, or text.
900  This should terminate with the current end tag.
901  */
902  const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
903 
904 private:
905 
907 };
908 
909 
912 class TiXmlComment : public TiXmlNode
913 {
914 public:
916  TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
917  TiXmlComment( const TiXmlComment& );
918  void operator=( const TiXmlComment& base );
919 
920  virtual ~TiXmlComment() {}
921 
923  virtual TiXmlNode* Clone() const;
925  virtual void Print( FILE* cfile, int depth ) const;
926 
927  /* Attribtue parsing starts: at the ! of the !--
928  returns: next char past '>'
929  */
930  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
931 
932 protected:
933  void CopyTo( TiXmlComment* target ) const;
934 
935  // used to be public
936  #ifdef TIXML_USE_STL
937  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
938  #endif
939  virtual void StreamOut( TIXML_OSTREAM * out ) const;
940 
941 private:
942 
943 };
944 
945 
948 class TiXmlText : public TiXmlNode
949 {
950  friend class TiXmlElement;
951 public:
953  TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
954  {
955  SetValue( initValue );
956  }
957  virtual ~TiXmlText() {}
958 
959  #ifdef TIXML_USE_STL
960  TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
962  {
963  SetValue( initValue );
964  }
965  #endif
966 
967  TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
968  void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
969 
971  virtual void Print( FILE* cfile, int depth ) const;
972 
973  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
974 
975 protected :
977  virtual TiXmlNode* Clone() const;
978  void CopyTo( TiXmlText* target ) const;
979 
980  virtual void StreamOut ( TIXML_OSTREAM * out ) const;
981  bool Blank() const; // returns true if all white space and new lines
982  // [internal use]
983  #ifdef TIXML_USE_STL
984  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
985  #endif
986 
987 private:
988 };
989 
990 
1005 {
1006 public:
1008  TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
1009 
1010 #ifdef TIXML_USE_STL
1011  TiXmlDeclaration( const std::string& _version,
1013  const std::string& _encoding,
1014  const std::string& _standalone );
1015 #endif
1016 
1018  TiXmlDeclaration( const char* _version,
1019  const char* _encoding,
1020  const char* _standalone );
1021 
1022  TiXmlDeclaration( const TiXmlDeclaration& copy );
1023  void operator=( const TiXmlDeclaration& copy );
1024 
1025  virtual ~TiXmlDeclaration() {}
1026 
1028  const char *Version() const { return version.c_str (); }
1030  const char *Encoding() const { return encoding.c_str (); }
1032  const char *Standalone() const { return standalone.c_str (); }
1033 
1035  virtual TiXmlNode* Clone() const;
1037  virtual void Print( FILE* cfile, int depth ) const;
1038 
1039  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1040 
1041 protected:
1042  void CopyTo( TiXmlDeclaration* target ) const;
1043  // used to be public
1044  #ifdef TIXML_USE_STL
1045  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1046  #endif
1047  virtual void StreamOut ( TIXML_OSTREAM * out) const;
1048 
1049 private:
1050 
1054 };
1055 
1056 
1064 class TiXmlUnknown : public TiXmlNode
1065 {
1066 public:
1067  TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
1068  virtual ~TiXmlUnknown() {}
1069 
1070  TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
1071  void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
1072 
1074  virtual TiXmlNode* Clone() const;
1076  virtual void Print( FILE* cfile, int depth ) const;
1077 
1078  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1079 
1080 protected:
1081  void CopyTo( TiXmlUnknown* target ) const;
1082 
1083  #ifdef TIXML_USE_STL
1084  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1085  #endif
1086  virtual void StreamOut ( TIXML_OSTREAM * out ) const;
1087 
1088 private:
1089 
1090 };
1091 
1092 
1097 class TiXmlDocument : public TiXmlNode
1098 {
1099 public:
1101  TiXmlDocument();
1103  TiXmlDocument( const char * documentName );
1104 
1105  #ifdef TIXML_USE_STL
1106  TiXmlDocument( const std::string& documentName );
1108  #endif
1109 
1110  TiXmlDocument( const TiXmlDocument& copy );
1111  void operator=( const TiXmlDocument& copy );
1112 
1113  virtual ~TiXmlDocument() {}
1114 
1119  bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1121  bool SaveFile() const;
1123  bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1125  bool SaveFile( const char * filename ) const;
1126 
1127  #ifdef TIXML_USE_STL
1128  bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
1129  {
1130  StringToBuffer f( filename );
1131  return ( f.buffer && LoadFile( f.buffer, encoding ));
1132  }
1133  bool SaveFile( const std::string& filename ) const
1134  {
1135  StringToBuffer f( filename );
1136  return ( f.buffer && SaveFile( f.buffer ));
1137  }
1138  #endif
1139 
1144  virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1145 
1150  TiXmlElement* RootElement() const { return FirstChildElement(); }
1151 
1157  bool Error() const { return error; }
1158 
1160  const char * ErrorDesc() const { return errorDesc.c_str (); }
1161 
1165  const int ErrorId() const { return errorId; }
1166 
1174  int ErrorRow() { return errorLocation.row+1; }
1175  int ErrorCol() { return errorLocation.col+1; }
1176 
1197  void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
1198 
1199  int TabSize() const { return tabsize; }
1200 
1204  void ClearError() { error = false;
1205  errorId = 0;
1206  errorDesc = "";
1207  errorLocation.row = errorLocation.col = 0;
1208  //errorLocation.last = 0;
1209  }
1210 
1212  void Print() const { Print( stdout, 0 ); }
1213 
1215  virtual void Print( FILE* cfile, int depth = 0 ) const;
1216  // [internal use]
1217  void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1218 
1219 protected :
1220  virtual void StreamOut ( TIXML_OSTREAM * out) const;
1221  // [internal use]
1222  virtual TiXmlNode* Clone() const;
1223  #ifdef TIXML_USE_STL
1224  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1225  #endif
1226 
1227 private:
1228  void CopyTo( TiXmlDocument* target ) const;
1229 
1230  bool error;
1231  int errorId;
1233  int tabsize;
1235 };
1236 
1237 
1319 {
1320 public:
1322  TiXmlHandle( TiXmlNode* node ) { this->node = node; }
1324  TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
1325  TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
1326 
1328  TiXmlHandle FirstChild() const;
1330  TiXmlHandle FirstChild( const char * value ) const;
1332  TiXmlHandle FirstChildElement() const;
1334  TiXmlHandle FirstChildElement( const char * value ) const;
1335 
1339  TiXmlHandle Child( const char* value, int index ) const;
1343  TiXmlHandle Child( int index ) const;
1348  TiXmlHandle ChildElement( const char* value, int index ) const;
1353  TiXmlHandle ChildElement( int index ) const;
1354 
1355  #ifdef TIXML_USE_STL
1356  TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
1357  TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
1358 
1359  TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
1360  TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
1361  #endif
1362 
1364  TiXmlNode* Node() const { return node; }
1366  TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
1368  TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
1370  TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
1371 
1372 private:
1374 };
1375 
1376 #ifdef __clang__
1377 #pragma clang diagnostic pop
1378 #endif
1379 
1380 #endif
1381 
1382 /*--- emacs style variables ---
1383  * Local Variables:
1384  * mode: C++
1385  * c-file-style: "ellemtel"
1386  * c-basic-offset: 4
1387  * tab-width: 8
1388  * indent-tabs-mode: nil
1389  * End:
1390  */
static const int utf8ByteTable[256]
Definition: tinyxml.h:192
TiXmlAttribute sentinel
Definition: tinyxml.h:771
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:985
Definition: tinyxml.h:640
int col
Definition: tinyxml.h:93
void SetUserData(void *user)
Definition: tinyxml.h:187
Definition: tinyxml.h:757
TiXmlUnknown(const TiXmlUnknown &copy)
Definition: tinyxml.h:1070
TiXmlComment()
Constructs an empty comment.
Definition: tinyxml.h:916
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
Definition: tinyxml.h:1324
TiXmlString standalone
Definition: tinyxml.h:1053
bool operator==(const TiXmlAttribute &rhs) const
Definition: tinyxml.h:716
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
Definition: tinyxml.h:664
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:672
TiXmlNode * prev
Definition: tinyxml.h:624
TiXmlHandle(TiXmlNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml.h:1322
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition: tinyxml.h:1160
bool operator<(const TiXmlAttribute &rhs) const
Definition: tinyxml.h:717
void Print() const
Definition: tinyxml.h:1212
static int ToLower(int v, TiXmlEncoding encoding)
Definition: tinyxml.h:322
TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:591
TiXmlElement * Element() const
Return the handle as a TiXmlElement. This may return null.
Definition: tinyxml.h:1366
TiXmlNode * firstChild
Definition: tinyxml.h:619
Definition: tinyxml.h:410
char chr
Definition: tinyxml.h:344
Definition: tinyxml.h:87
void operator=(const TiXmlUnknown &copy)
Definition: tinyxml.h:1071
Definition: tinyxml.h:102
Definition: tinyxml.h:412
TiXmlNode * Parent() const
One step up the DOM.
Definition: tinyxml.h:456
TiXmlDocument * document
Definition: tinyxml.h:737
Definition: tinyxml.h:296
bool Error() const
Definition: tinyxml.h:1157
int Column() const
See Row()
Definition: tinyxml.h:185
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Definition: tinyxml.cpp:272
void SetName(const char *_name)
Set the name of this attribute.
Definition: tinyxml.h:690
void SetTabSize(int _tabsize)
Definition: tinyxml.h:1197
TiXmlAttribute()
Construct an empty attribute.
Definition: tinyxml.h:646
int ErrorRow()
Definition: tinyxml.h:1174
const int TIXML_PATCH_VERSION
Definition: tinyxml.h:82
const char * Standalone() const
Is this a standalone document?
Definition: tinyxml.h:1032
void CopyTo(TiXmlElement *target) const
Definition: tinyxml.cpp:704
virtual ~TiXmlText()
Definition: tinyxml.h:957
void ClearError()
Definition: tinyxml.h:1204
void Clear()
Definition: tinyxml.h:90
TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cpp:403
void CopyTo(TiXmlUnknown *target) const
Definition: tinyxml.cpp:1209
virtual ~TiXmlComment()
Definition: tinyxml.h:920
virtual int Type() const
Definition: tinyxml.h:576
void SetValue(const char *_value)
Definition: tinyxml.h:441
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Definition: tinyxml.cpp:210
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Definition: tinyxml.cpp:220
static bool condenseWhiteSpace
Definition: tinyxml.h:353
Definition: tinyxml.h:109
virtual ~TiXmlDocument()
Definition: tinyxml.h:1113
NodeType
Definition: tinyxml.h:405
TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:590
TiXmlComment * ToComment() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:588
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Definition: tinyxml.cpp:193
TiXmlElement * RootElement() const
Definition: tinyxml.h:1150
const char * Encoding() const
Encoding. Will return an empty string if none was found.
Definition: tinyxml.h:1030
void * userData
Field containing a generic user pointer.
Definition: tinyxml.h:316
TiXmlAttribute * prev
Definition: tinyxml.h:740
const char * str
Definition: tinyxml.h:342
Definition: tinyxml.h:1004
#define TIXML_OSTREAM
Definition: tinyxml.h:68
Definition: tinyxml.h:110
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:673
static bool IsWhiteSpace(char c)
Definition: tinyxml.h:211
TiXmlCursor()
Definition: tinyxml.h:89
TiXmlElement * NextSiblingElement() const
Definition: tinyxml.cpp:432
TiXmlAttributeSet attributeSet
Definition: tinyxml.h:906
TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:458
Definition: tinyxml.h:1064
const TiXmlEncoding TIXML_DEFAULT_ENCODING
Definition: tinyxml.h:114
Definition: tinyxml.h:340
TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:587
TiXmlAttribute * Last() const
Definition: tinyxml.h:767
TiXmlUnknown()
Definition: tinyxml.h:1067
const char * Version() const
Version. Will return an empty string if none was found.
Definition: tinyxml.h:1028
TiXmlAttribute * next
Definition: tinyxml.h:741
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
Definition: tinyxml.h:164
TiXmlText(const TiXmlText &copy)
Definition: tinyxml.h:967
TiXmlCursor location
Definition: tinyxml.h:313
const char * Value() const
Definition: tinyxml.h:430
const int TIXML_MAJOR_VERSION
Definition: tinyxml.h:80
Definition: tinyxml.h:100
virtual ~TiXmlUnknown()
Definition: tinyxml.h:1068
int ErrorCol()
The column where the error occured. See ErrorRow()
Definition: tinyxml.h:1175
virtual void StreamOut(TiXmlOutStream *out) const
Definition: tinyxml.cpp:673
void CopyTo(TiXmlText *target) const
Definition: tinyxml.cpp:1077
const int ErrorId() const
Definition: tinyxml.h:1165
TiXmlString errorDesc
Definition: tinyxml.h:1232
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:622
int tabsize
Definition: tinyxml.h:1233
Definition: tinyxml.h:1097
TiXmlString value
Definition: tinyxml.h:739
TiXmlEncoding
Definition: tinyxml.h:107
const TiXmlString & SValue() const
Definition: tinyxml.h:614
int row
Definition: tinyxml.h:92
Definition: tinyxml.h:301
const char * c_str() const
Definition: tinystr.h:70
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:776
TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:589
TiXmlNode * LastChild() const
Definition: tinyxml.h:461
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Definition: tinyxml.cpp:246
TiXmlUnknown * Unknown() const
Return the handle as a TiXmlUnknown. This may return null;.
Definition: tinyxml.h:1370
int Row() const
Definition: tinyxml.h:184
TiXmlNode * node
Definition: tinyxml.h:1373
Definition: tinyxml.h:411
Definition: tinyxml.h:1318
char * buffer
Definition: tinyxml.h:207
TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:586
TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:530
TiXmlOutStream & operator<<(TiXmlOutStream &out, const TiXmlNode &base)
Definition: tinyxml.cpp:1296
static void SetCondenseWhiteSpace(bool condense)
Definition: tinyxml.h:161
bool operator>(const TiXmlAttribute &rhs) const
Definition: tinyxml.h:718
Definition: tinyxml.h:138
Definition: tinyxml.h:307
virtual ~TiXmlBase()
Definition: tinyxml.h:146
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxmlparser.cpp:668
void operator=(const TiXmlElement &base)
Definition: tinyxml.cpp:501
Definition: tinyxml.h:413
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
Definition: tinyxml.cpp:727
TiXmlHandle operator=(const TiXmlHandle &ref)
Definition: tinyxml.h:1325
TiXmlNode * parent
Definition: tinyxml.h:616
TiXmlNode(NodeType _type)
Definition: tinyxml.cpp:144
TiXmlString version
Definition: tinyxml.h:1051
void * GetUserData()
Definition: tinyxml.h:188
Definition: tinyxml.h:363
Definition: tinyxmlparser.cpp:149
Definition: tinyxml.h:408
Definition: tinyxml.h:202
Definition: tinyxml.h:101
bool error
Definition: tinyxml.h:1230
Definition: tinyxml.h:948
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml.h:584
TiXmlNode * Node() const
Return the handle as a TiXmlNode. This may return null.
Definition: tinyxml.h:1364
TiXmlString encoding
Definition: tinyxml.h:1052
TiXmlNode * next
Definition: tinyxml.h:625
int TabSize() const
Definition: tinyxml.h:1199
TiXmlNode * IterateChildren(TiXmlNode *previous) const
The last child of this node matching &#39;value&#39;. Will be null if there are no children.
Definition: tinyxml.cpp:344
static const char * GetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)
Definition: tinyxml.h:244
void operator=(const TiXmlText &base)
Definition: tinyxml.h:968
TiXmlText(const char *initValue)
Constructor.
Definition: tinyxml.h:953
Definition: tinyxml.h:294
Definition: tinyxml.h:409
unsigned int strLength
Definition: tinyxml.h:343
NodeType type
Definition: tinyxml.h:617
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
Definition: tinyxml.cpp:300
Definition: tinyxml.h:295
Definition: tinyxml.h:912
void SetDocument(TiXmlDocument *doc)
Definition: tinyxml.h:731
TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
Definition: tinyxml.h:875
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:691
virtual ~TiXmlDeclaration()
Definition: tinyxml.h:1025
Definition: tinyxml.h:407
TiXmlNode * lastChild
Definition: tinyxml.h:620
TiXmlDocument * GetDocument() const
Definition: tinyxml.cpp:462
TiXmlDeclaration()
Construct an empty declaration.
Definition: tinyxml.h:1008
TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
Definition: tinyxml.h:874
TiXmlString name
Definition: tinyxml.h:738
virtual ~TiXmlNode()
Definition: tinyxml.cpp:155
int errorId
Definition: tinyxml.h:1231
TiXmlString value
Definition: tinyxml.h:622
TiXmlAttribute * First() const
Definition: tinyxml.h:766
TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:541
#define TIXML_STRING
Definition: tinyxml.h:67
const int TIXML_MINOR_VERSION
Definition: tinyxml.h:81
TiXmlText * Text() const
Return the handle as a TiXmlText. This may return null.
Definition: tinyxml.h:1368
Definition: tinyxml.h:779
TiXmlCursor errorLocation
Definition: tinyxml.h:1234
TiXmlBase()
Definition: tinyxml.h:145
Definition: tinyxml.h:111
Definition: tinyxml.h:306