00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #ifndef TINYXML_INCLUDED
00031 #define TINYXML_INCLUDED
00032
00033 #ifdef _MSC_VER
00034 #pragma warning( disable : 4530 )
00035 #pragma warning( disable : 4786 )
00036 #endif
00037
00038 #include <ctype.h>
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <string.h>
00042 #include <assert.h>
00043
00044
00045 #if defined( _DEBUG ) && !defined( DEBUG )
00046 #define DEBUG
00047 #endif
00048
00049 #if defined( DEBUG ) && defined( _MSC_VER )
00050 #include <windows.h>
00051 #define TIXML_LOG OutputDebugString
00052 #else
00053 #define TIXML_LOG printf
00054 #endif
00055
00056 #ifdef TIXML_USE_STL
00057 #include <string>
00058 #include <iostream>
00059 #define TIXML_STRING std::string
00060 #define TIXML_ISTREAM std::istream
00061 #define TIXML_OSTREAM std::ostream
00062 #else
00063 #include "tinystr.h"
00064 #define TIXML_STRING TiXmlString
00065 #define TIXML_OSTREAM TiXmlOutStream
00066 #endif
00067
00068
00069
00070 #ifdef __BORLANDC__
00071 #pragma option push -b
00072 #pragma option push -a4
00073 #endif
00074
00075 class TiXmlDocument;
00076 class TiXmlElement;
00077 class TiXmlComment;
00078 class TiXmlUnknown;
00079 class TiXmlAttribute;
00080 class TiXmlText;
00081 class TiXmlDeclaration;
00082 class TiXmlParsingData;
00083
00084 const int TIXML_MAJOR_VERSION = 2;
00085 const int TIXML_MINOR_VERSION = 3;
00086 const int TIXML_PATCH_VERSION = 2;
00087
00088
00089
00090
00091 struct TiXmlCursor
00092 {
00093 TiXmlCursor() { Clear(); }
00094 void Clear() { row = col = -1; }
00095
00096 int row;
00097 int col;
00098 };
00099
00100
00101
00102 enum
00103 {
00104 TIXML_SUCCESS,
00105 TIXML_NO_ATTRIBUTE,
00106 TIXML_WRONG_TYPE
00107 };
00108
00109
00110
00111 enum TiXmlEncoding
00112 {
00113 TIXML_ENCODING_UNKNOWN,
00114 TIXML_ENCODING_UTF8,
00115 TIXML_ENCODING_LEGACY
00116 };
00117
00118 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00119
00142 class TiXmlBase
00143 {
00144 friend class TiXmlNode;
00145 friend class TiXmlElement;
00146 friend class TiXmlDocument;
00147
00148 public:
00149 TiXmlBase() : userData(0) {}
00150 virtual ~TiXmlBase() {}
00151
00157 virtual void Print( FILE* cfile, int depth ) const = 0;
00158
00165 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00166
00168 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00169
00188 int Row() const { return location.row + 1; }
00189 int Column() const { return location.col + 1; }
00190
00191 void SetUserData( void* user ) { userData = user; }
00192 void* GetUserData() { return userData; }
00193
00194
00195
00196 static const int utf8ByteTable[256];
00197
00198 virtual const char* Parse( const char* p,
00199 TiXmlParsingData* data,
00200 TiXmlEncoding encoding ) = 0;
00201
00202 protected:
00203
00204
00205
00206 class StringToBuffer
00207 {
00208 public:
00209 StringToBuffer( const TIXML_STRING& str );
00210 ~StringToBuffer();
00211 char* buffer;
00212 };
00213
00214 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00215 inline static bool IsWhiteSpace( char c )
00216 {
00217 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00218 }
00219
00220 virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00221
00222 #ifdef TIXML_USE_STL
00223 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00224 static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00225 #endif
00226
00227
00228
00229
00230
00231 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00232
00233
00234
00235
00236 static const char* ReadText( const char* in,
00237 TIXML_STRING* text,
00238 bool ignoreWhiteSpace,
00239 const char* endTag,
00240 bool ignoreCase,
00241 TiXmlEncoding encoding );
00242
00243
00244 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00245
00246
00247
00248 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00249 {
00250 assert( p );
00251 if ( encoding == TIXML_ENCODING_UTF8 )
00252 {
00253 *length = utf8ByteTable[ *((unsigned char*)p) ];
00254 assert( *length >= 0 && *length < 5 );
00255 }
00256 else
00257 {
00258 *length = 1;
00259 }
00260
00261 if ( *length == 1 )
00262 {
00263 if ( *p == '&' )
00264 return GetEntity( p, _value, length, encoding );
00265 *_value = *p;
00266 return p+1;
00267 }
00268 else if ( *length )
00269 {
00270 strncpy( _value, p, *length );
00271 return p + (*length);
00272 }
00273 else
00274 {
00275
00276 return 0;
00277 }
00278 }
00279
00280
00281
00282 static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00283
00284 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00285
00286
00287
00288
00289 static bool StringEqual( const char* p,
00290 const char* endTag,
00291 bool ignoreCase,
00292 TiXmlEncoding encoding );
00293
00294
00295 enum
00296 {
00297 TIXML_NO_ERROR = 0,
00298 TIXML_ERROR,
00299 TIXML_ERROR_OPENING_FILE,
00300 TIXML_ERROR_OUT_OF_MEMORY,
00301 TIXML_ERROR_PARSING_ELEMENT,
00302 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00303 TIXML_ERROR_READING_ELEMENT_VALUE,
00304 TIXML_ERROR_READING_ATTRIBUTES,
00305 TIXML_ERROR_PARSING_EMPTY,
00306 TIXML_ERROR_READING_END_TAG,
00307 TIXML_ERROR_PARSING_UNKNOWN,
00308 TIXML_ERROR_PARSING_COMMENT,
00309 TIXML_ERROR_PARSING_DECLARATION,
00310 TIXML_ERROR_DOCUMENT_EMPTY,
00311 TIXML_ERROR_EMBEDDED_NULL,
00312
00313 TIXML_ERROR_STRING_COUNT,
00314 TIXML_ERROR_MAXRANGE = 0x12345678
00315 };
00316 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00317
00318 TiXmlCursor location;
00319
00321 void* userData;
00322
00323
00324
00325 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00326 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00327 inline static int ToLower( int v, TiXmlEncoding encoding )
00328 {
00329 if ( encoding == TIXML_ENCODING_UTF8 )
00330 {
00331 if ( v < 128 ) return tolower( v );
00332 return v;
00333 }
00334 else
00335 {
00336 return tolower( v );
00337 }
00338 }
00339 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00340
00341 private:
00342 TiXmlBase( const TiXmlBase& );
00343 void operator=( const TiXmlBase& base );
00344
00345 struct Entity
00346 {
00347 const char* str;
00348 unsigned int strLength;
00349 char chr;
00350 };
00351 enum
00352 {
00353 NUM_ENTITY = 5,
00354 MAX_ENTITY_LENGTH = 6
00355
00356 };
00357 static Entity entity[ NUM_ENTITY ];
00358 static bool condenseWhiteSpace;
00359 };
00360
00361
00368 class TiXmlNode : public TiXmlBase
00369 {
00370 friend class TiXmlDocument;
00371 friend class TiXmlElement;
00372
00373 public:
00374 #ifdef TIXML_USE_STL
00375
00379 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00380
00397 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00398
00400 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00401
00402 #else
00403
00404 friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00405 #endif
00406
00410 enum NodeType
00411 {
00412 DOCUMENT,
00413 ELEMENT,
00414 COMMENT,
00415 UNKNOWN,
00416 TEXT,
00417 DECLARATION,
00418 TYPECOUNT
00419 };
00420
00421 virtual ~TiXmlNode();
00422
00435 const char * Value() const { return value.c_str (); }
00436
00446 void SetValue(const char * _value) { value = _value;}
00447
00448 #ifdef TIXML_USE_STL
00449
00450 void SetValue( const std::string& _value )
00451 {
00452 StringToBuffer buf( _value );
00453 SetValue( buf.buffer ? buf.buffer : "" );
00454 }
00455 #endif
00456
00458 void Clear();
00459
00461 TiXmlNode* Parent() const { return parent; }
00462
00463 TiXmlNode* FirstChild() const { return firstChild; }
00464 TiXmlNode* FirstChild( const char * value ) const;
00465
00466 TiXmlNode* LastChild() const { return lastChild; }
00467 TiXmlNode* LastChild( const char * value ) const;
00468
00469 #ifdef TIXML_USE_STL
00470 TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00471 TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00472 #endif
00473
00490 TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
00491
00493 TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
00494
00495 #ifdef TIXML_USE_STL
00496 TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00497 #endif
00498
00502 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00503
00504
00514 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00515
00519 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00520
00524 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00525
00529 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00530
00532 bool RemoveChild( TiXmlNode* removeThis );
00533
00535 TiXmlNode* PreviousSibling() const { return prev; }
00536
00538 TiXmlNode* PreviousSibling( const char * ) const;
00539
00540 #ifdef TIXML_USE_STL
00541 TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00542 TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00543 #endif
00544
00546 TiXmlNode* NextSibling() const { return next; }
00547
00549 TiXmlNode* NextSibling( const char * ) const;
00550
00555 TiXmlElement* NextSiblingElement() const;
00556
00561 TiXmlElement* NextSiblingElement( const char * ) const;
00562
00563 #ifdef TIXML_USE_STL
00564 TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00565 #endif
00566
00568 TiXmlElement* FirstChildElement() const;
00569
00571 TiXmlElement* FirstChildElement( const char * value ) const;
00572
00573 #ifdef TIXML_USE_STL
00574 TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00575 #endif
00576
00581 virtual int Type() const { return type; }
00582
00586 TiXmlDocument* GetDocument() const;
00587
00589 bool NoChildren() const { return !firstChild; }
00590
00591 TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
00592 TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
00593 TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
00594 TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
00595 TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
00596 TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
00597
00601 virtual TiXmlNode* Clone() const = 0;
00602
00603 protected:
00604 TiXmlNode( NodeType _type );
00605
00606
00607
00608 void CopyTo( TiXmlNode* target ) const;
00609
00610 #ifdef TIXML_USE_STL
00611
00612 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00613 #endif
00614
00615
00616 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00617
00618
00619 const TIXML_STRING& SValue() const { return value ; }
00620
00621 TiXmlNode* parent;
00622 NodeType type;
00623
00624 TiXmlNode* firstChild;
00625 TiXmlNode* lastChild;
00626
00627 TIXML_STRING value;
00628
00629 TiXmlNode* prev;
00630 TiXmlNode* next;
00631
00632 private:
00633 TiXmlNode( const TiXmlNode& );
00634 void operator=( const TiXmlNode& base );
00635 };
00636
00637
00645 class TiXmlAttribute : public TiXmlBase
00646 {
00647 friend class TiXmlAttributeSet;
00648
00649 public:
00651 TiXmlAttribute() : TiXmlBase()
00652 {
00653 document = 0;
00654 prev = next = 0;
00655 }
00656
00657 #ifdef TIXML_USE_STL
00658
00659 TiXmlAttribute( const std::string& _name, const std::string& _value )
00660 {
00661 name = _name;
00662 value = _value;
00663 document = 0;
00664 prev = next = 0;
00665 }
00666 #endif
00667
00669 TiXmlAttribute( const char * _name, const char * _value )
00670 {
00671 name = _name;
00672 value = _value;
00673 document = 0;
00674 prev = next = 0;
00675 }
00676
00677 const char* Name() const { return name.c_str (); }
00678 const char* Value() const { return value.c_str (); }
00679 const int IntValue() const;
00680 const double DoubleValue() const;
00681
00691 int QueryIntValue( int* value ) const;
00693 int QueryDoubleValue( double* value ) const;
00694
00695 void SetName( const char* _name ) { name = _name; }
00696 void SetValue( const char* _value ) { value = _value; }
00697
00698 void SetIntValue( int value );
00699 void SetDoubleValue( double value );
00700
00701 #ifdef TIXML_USE_STL
00702
00703 void SetName( const std::string& _name )
00704 {
00705 StringToBuffer buf( _name );
00706 SetName ( buf.buffer ? buf.buffer : "error" );
00707 }
00709 void SetValue( const std::string& _value )
00710 {
00711 StringToBuffer buf( _value );
00712 SetValue( buf.buffer ? buf.buffer : "error" );
00713 }
00714 #endif
00715
00717 TiXmlAttribute* Next() const;
00719 TiXmlAttribute* Previous() const;
00720
00721 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00722 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00723 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00724
00725
00726
00727
00728 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00729
00730
00731 virtual void Print( FILE* cfile, int depth ) const;
00732
00733 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00734
00735
00736 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00737
00738 private:
00739 TiXmlAttribute( const TiXmlAttribute& );
00740 void operator=( const TiXmlAttribute& base );
00741
00742 TiXmlDocument* document;
00743 TIXML_STRING name;
00744 TIXML_STRING value;
00745 TiXmlAttribute* prev;
00746 TiXmlAttribute* next;
00747 };
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762 class TiXmlAttributeSet
00763 {
00764 public:
00765 TiXmlAttributeSet();
00766 ~TiXmlAttributeSet();
00767
00768 void Add( TiXmlAttribute* attribute );
00769 void Remove( TiXmlAttribute* attribute );
00770
00771 TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00772 TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00773 TiXmlAttribute* Find( const char * name ) const;
00774
00775 private:
00776 TiXmlAttribute sentinel;
00777 };
00778
00779
00784 class TiXmlElement : public TiXmlNode
00785 {
00786 public:
00788 TiXmlElement (const char * in_value);
00789
00790 #ifdef TIXML_USE_STL
00791
00792 TiXmlElement( const std::string& _value );
00793 #endif
00794
00795 TiXmlElement( const TiXmlElement& );
00796
00797 void operator=( const TiXmlElement& base );
00798
00799 virtual ~TiXmlElement();
00800
00804 const char* Attribute( const char* name ) const;
00805
00812 const char* Attribute( const char* name, int* i ) const;
00813
00820 const char* Attribute( const char* name, double* d ) const;
00821
00829 int QueryIntAttribute( const char* name, int* value ) const;
00831 int QueryDoubleAttribute( const char* name, double* value ) const;
00832
00836 void SetAttribute( const char* name, const char * value );
00837
00838 #ifdef TIXML_USE_STL
00839 const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
00840 const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
00841 const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); }
00842 int QueryIntAttribute( const std::string& name, int* value ) const { return QueryIntAttribute( name.c_str(), value ); }
00843 int QueryDoubleAttribute( const std::string& name, double* value ) const { return QueryDoubleAttribute( name.c_str(), value ); }
00844
00846 void SetAttribute( const std::string& name, const std::string& _value )
00847 {
00848 StringToBuffer n( name );
00849 StringToBuffer v( _value );
00850 if ( n.buffer && v.buffer )
00851 SetAttribute (n.buffer, v.buffer );
00852 }
00854 void SetAttribute( const std::string& name, int _value )
00855 {
00856 StringToBuffer n( name );
00857 if ( n.buffer )
00858 SetAttribute (n.buffer, _value);
00859 }
00860 #endif
00861
00865 void SetAttribute( const char * name, int value );
00866
00870 void SetDoubleAttribute( const char * name, double value );
00871
00874 void RemoveAttribute( const char * name );
00875 #ifdef TIXML_USE_STL
00876 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
00877 #endif
00878
00879 TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
00880 TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
00881
00883 virtual TiXmlNode* Clone() const;
00884
00885 virtual void Print( FILE* cfile, int depth ) const;
00886
00887
00888
00889
00890 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00891
00892 protected:
00893
00894 void CopyTo( TiXmlElement* target ) const;
00895 void ClearThis();
00896
00897
00898 #ifdef TIXML_USE_STL
00899 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00900 #endif
00901 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00902
00903
00904
00905
00906
00907 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
00908
00909 private:
00910
00911 TiXmlAttributeSet attributeSet;
00912 };
00913
00914
00917 class TiXmlComment : public TiXmlNode
00918 {
00919 public:
00921 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
00922 TiXmlComment( const TiXmlComment& );
00923 void operator=( const TiXmlComment& base );
00924
00925 virtual ~TiXmlComment() {}
00926
00928 virtual TiXmlNode* Clone() const;
00930 virtual void Print( FILE* cfile, int depth ) const;
00931
00932
00933
00934
00935 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00936
00937 protected:
00938 void CopyTo( TiXmlComment* target ) const;
00939
00940
00941 #ifdef TIXML_USE_STL
00942 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00943 #endif
00944 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00945
00946 private:
00947
00948 };
00949
00950
00953 class TiXmlText : public TiXmlNode
00954 {
00955 friend class TiXmlElement;
00956 public:
00958 TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
00959 {
00960 SetValue( initValue );
00961 }
00962 virtual ~TiXmlText() {}
00963
00964 #ifdef TIXML_USE_STL
00965
00966 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
00967 {
00968 SetValue( initValue );
00969 }
00970 #endif
00971
00972 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
00973 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
00974
00976 virtual void Print( FILE* cfile, int depth ) const;
00977
00978 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00979
00980 protected :
00982 virtual TiXmlNode* Clone() const;
00983 void CopyTo( TiXmlText* target ) const;
00984
00985 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00986 bool Blank() const;
00987
00988 #ifdef TIXML_USE_STL
00989 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00990 #endif
00991
00992 private:
00993 };
00994
00995
01009 class TiXmlDeclaration : public TiXmlNode
01010 {
01011 public:
01013 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01014
01015 #ifdef TIXML_USE_STL
01016
01017 TiXmlDeclaration( const std::string& _version,
01018 const std::string& _encoding,
01019 const std::string& _standalone );
01020 #endif
01021
01023 TiXmlDeclaration( const char* _version,
01024 const char* _encoding,
01025 const char* _standalone );
01026
01027 TiXmlDeclaration( const TiXmlDeclaration& copy );
01028 void operator=( const TiXmlDeclaration& copy );
01029
01030 virtual ~TiXmlDeclaration() {}
01031
01033 const char *Version() const { return version.c_str (); }
01035 const char *Encoding() const { return encoding.c_str (); }
01037 const char *Standalone() const { return standalone.c_str (); }
01038
01040 virtual TiXmlNode* Clone() const;
01042 virtual void Print( FILE* cfile, int depth ) const;
01043
01044 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01045
01046 protected:
01047 void CopyTo( TiXmlDeclaration* target ) const;
01048
01049 #ifdef TIXML_USE_STL
01050 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01051 #endif
01052 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01053
01054 private:
01055
01056 TIXML_STRING version;
01057 TIXML_STRING encoding;
01058 TIXML_STRING standalone;
01059 };
01060
01061
01069 class TiXmlUnknown : public TiXmlNode
01070 {
01071 public:
01072 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01073 virtual ~TiXmlUnknown() {}
01074
01075 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01076 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01077
01079 virtual TiXmlNode* Clone() const;
01081 virtual void Print( FILE* cfile, int depth ) const;
01082
01083 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01084
01085 protected:
01086 void CopyTo( TiXmlUnknown* target ) const;
01087
01088 #ifdef TIXML_USE_STL
01089 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01090 #endif
01091 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01092
01093 private:
01094
01095 };
01096
01097
01102 class TiXmlDocument : public TiXmlNode
01103 {
01104 public:
01106 TiXmlDocument();
01108 TiXmlDocument( const char * documentName );
01109
01110 #ifdef TIXML_USE_STL
01111
01112 TiXmlDocument( const std::string& documentName );
01113 #endif
01114
01115 TiXmlDocument( const TiXmlDocument& copy );
01116 void operator=( const TiXmlDocument& copy );
01117
01118 virtual ~TiXmlDocument() {}
01119
01124 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01126 bool SaveFile() const;
01128 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01130 bool SaveFile( const char * filename ) const;
01131
01132 #ifdef TIXML_USE_STL
01133 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01134 {
01135 StringToBuffer f( filename );
01136 return ( f.buffer && LoadFile( f.buffer, encoding ));
01137 }
01138 bool SaveFile( const std::string& filename ) const
01139 {
01140 StringToBuffer f( filename );
01141 return ( f.buffer && SaveFile( f.buffer ));
01142 }
01143 #endif
01144
01149 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01150
01155 TiXmlElement* RootElement() const { return FirstChildElement(); }
01156
01162 bool Error() const { return error; }
01163
01165 const char * ErrorDesc() const { return errorDesc.c_str (); }
01166
01170 const int ErrorId() const { return errorId; }
01171
01179 int ErrorRow() { return errorLocation.row+1; }
01180 int ErrorCol() { return errorLocation.col+1; }
01181
01202 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01203
01204 int TabSize() const { return tabsize; }
01205
01209 void ClearError() { error = false;
01210 errorId = 0;
01211 errorDesc = "";
01212 errorLocation.row = errorLocation.col = 0;
01213
01214 }
01215
01217 void Print() const { Print( stdout, 0 ); }
01218
01220 virtual void Print( FILE* cfile, int depth = 0 ) const;
01221
01222 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01223
01224 protected :
01225 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01226
01227 virtual TiXmlNode* Clone() const;
01228 #ifdef TIXML_USE_STL
01229 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01230 #endif
01231
01232 private:
01233 void CopyTo( TiXmlDocument* target ) const;
01234
01235 bool error;
01236 int errorId;
01237 TIXML_STRING errorDesc;
01238 int tabsize;
01239 TiXmlCursor errorLocation;
01240 };
01241
01242
01323 class TiXmlHandle
01324 {
01325 public:
01327 TiXmlHandle( TiXmlNode* node ) { this->node = node; }
01329 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01330 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01331
01333 TiXmlHandle FirstChild() const;
01335 TiXmlHandle FirstChild( const char * value ) const;
01337 TiXmlHandle FirstChildElement() const;
01339 TiXmlHandle FirstChildElement( const char * value ) const;
01340
01344 TiXmlHandle Child( const char* value, int index ) const;
01348 TiXmlHandle Child( int index ) const;
01353 TiXmlHandle ChildElement( const char* value, int index ) const;
01358 TiXmlHandle ChildElement( int index ) const;
01359
01360 #ifdef TIXML_USE_STL
01361 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01362 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01363
01364 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01365 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01366 #endif
01367
01369 TiXmlNode* Node() const { return node; }
01371 TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01373 TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01375 TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01376
01377 private:
01378 TiXmlNode* node;
01379 };
01380
01385 #ifdef __BORLANDC__
01386 #pragma option pop
01387 #pragma option pop
01388 #endif
01389
01390 #endif
01391
01392
01393
01394
01395
01396
01397
01398
01399