00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef TINYXML_INCLUDED
00027 #define TINYXML_INCLUDED
00028
00029 #ifdef _MSC_VER
00030 #pragma warning( disable : 4530 )
00031 #pragma warning( disable : 4786 )
00032 #endif
00033
00034 #include <ctype.h>
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include <assert.h>
00039
00040
00041 #if defined( _DEBUG ) && !defined( DEBUG )
00042 #define DEBUG
00043 #endif
00044
00045 #if defined( DEBUG ) && defined( _MSC_VER )
00046 #include <windows.h>
00047 #define TIXML_LOG OutputDebugString
00048 #else
00049 #define TIXML_LOG printf
00050 #endif
00051
00052 #ifdef TIXML_USE_STL
00053 #include <string>
00054 #include <iostream>
00055 #define TIXML_STRING std::string
00056 #define TIXML_ISTREAM std::istream
00057 #define TIXML_OSTREAM std::ostream
00058 #else
00059 #include "tinystr.h"
00060 #define TIXML_STRING TiXmlString
00061 #define TIXML_OSTREAM TiXmlOutStream
00062 #endif
00063
00064 class TiXmlDocument;
00065 class TiXmlElement;
00066 class TiXmlComment;
00067 class TiXmlUnknown;
00068 class TiXmlAttribute;
00069 class TiXmlText;
00070 class TiXmlDeclaration;
00071 class TiXmlParsingData;
00072
00073 const int TIXML_MAJOR_VERSION = 2;
00074 const int TIXML_MINOR_VERSION = 3;
00075 const int TIXML_PATCH_VERSION = 2;
00076
00077
00078
00079
00080 struct TiXmlCursor
00081 {
00082 TiXmlCursor() { Clear(); }
00083 void Clear() { row = col = -1; }
00084
00085 int row;
00086 int col;
00087 };
00088
00089
00090
00091 enum
00092 {
00093 TIXML_SUCCESS,
00094 TIXML_NO_ATTRIBUTE,
00095 TIXML_WRONG_TYPE
00096 };
00097
00098
00099
00100 enum TiXmlEncoding
00101 {
00102 TIXML_ENCODING_UNKNOWN,
00103 TIXML_ENCODING_UTF8,
00104 TIXML_ENCODING_LEGACY
00105 };
00106
00107 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00108
00131 class TiXmlBase
00132 {
00133 friend class TiXmlNode;
00134 friend class TiXmlElement;
00135 friend class TiXmlDocument;
00136
00137 public:
00138 TiXmlBase() : userData(0) {}
00139 virtual ~TiXmlBase() {}
00140
00146 virtual void Print( FILE* cfile, int depth ) const = 0;
00147
00154 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00155
00157 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00158
00177 int Row() const { return location.row + 1; }
00178 int Column() const { return location.col + 1; }
00179
00180 void SetUserData( void* user ) { userData = user; }
00181 void* GetUserData() { return userData; }
00182
00183
00184
00185 static const int utf8ByteTable[256];
00186
00187 virtual const char* Parse( const char* p,
00188 TiXmlParsingData* data,
00189 TiXmlEncoding encoding ) = 0;
00190
00191 protected:
00192
00193
00194
00195 class StringToBuffer
00196 {
00197 public:
00198 StringToBuffer( const TIXML_STRING& str );
00199 ~StringToBuffer();
00200 char* buffer;
00201 };
00202
00203 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00204 inline static bool IsWhiteSpace( char c )
00205 {
00206 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00207 }
00208
00209 virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00210
00211 #ifdef TIXML_USE_STL
00212 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00213 static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00214 #endif
00215
00216
00217
00218
00219
00220 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00221
00222
00223
00224
00225 static const char* ReadText( const char* in,
00226 TIXML_STRING* text,
00227 bool ignoreWhiteSpace,
00228 const char* endTag,
00229 bool ignoreCase,
00230 TiXmlEncoding encoding );
00231
00232
00233 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00234
00235
00236
00237 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00238 {
00239 assert( p );
00240 if ( encoding == TIXML_ENCODING_UTF8 )
00241 {
00242 *length = utf8ByteTable[ *((unsigned char*)p) ];
00243 assert( *length >= 0 && *length < 5 );
00244 }
00245 else
00246 {
00247 *length = 1;
00248 }
00249
00250 if ( *length == 1 )
00251 {
00252 if ( *p == '&' )
00253 return GetEntity( p, _value, length, encoding );
00254 *_value = *p;
00255 return p+1;
00256 }
00257 else if ( *length )
00258 {
00259 strncpy( _value, p, *length );
00260 return p + (*length);
00261 }
00262 else
00263 {
00264
00265 return 0;
00266 }
00267 }
00268
00269
00270
00271 static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00272
00273 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00274
00275
00276
00277
00278 static bool StringEqual( const char* p,
00279 const char* endTag,
00280 bool ignoreCase,
00281 TiXmlEncoding encoding );
00282
00283
00284 enum
00285 {
00286 TIXML_NO_ERROR = 0,
00287 TIXML_ERROR,
00288 TIXML_ERROR_OPENING_FILE,
00289 TIXML_ERROR_OUT_OF_MEMORY,
00290 TIXML_ERROR_PARSING_ELEMENT,
00291 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00292 TIXML_ERROR_READING_ELEMENT_VALUE,
00293 TIXML_ERROR_READING_ATTRIBUTES,
00294 TIXML_ERROR_PARSING_EMPTY,
00295 TIXML_ERROR_READING_END_TAG,
00296 TIXML_ERROR_PARSING_UNKNOWN,
00297 TIXML_ERROR_PARSING_COMMENT,
00298 TIXML_ERROR_PARSING_DECLARATION,
00299 TIXML_ERROR_DOCUMENT_EMPTY,
00300 TIXML_ERROR_EMBEDDED_NULL,
00301
00302 TIXML_ERROR_STRING_COUNT
00303 };
00304 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00305
00306 TiXmlCursor location;
00307
00309 void* userData;
00310
00311
00312
00313 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00314 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00315 inline static int ToLower( int v, TiXmlEncoding encoding )
00316 {
00317 if ( encoding == TIXML_ENCODING_UTF8 )
00318 {
00319 if ( v < 128 ) return tolower( v );
00320 return v;
00321 }
00322 else
00323 {
00324 return tolower( v );
00325 }
00326 }
00327 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00328
00329 private:
00330 TiXmlBase( const TiXmlBase& );
00331 void operator=( const TiXmlBase& base );
00332
00333 struct Entity
00334 {
00335 const char* str;
00336 unsigned int strLength;
00337 char chr;
00338 };
00339 enum
00340 {
00341 NUM_ENTITY = 5,
00342 MAX_ENTITY_LENGTH = 6
00343
00344 };
00345 static Entity entity[ NUM_ENTITY ];
00346 static bool condenseWhiteSpace;
00347 };
00348
00349
00356 class TiXmlNode : public TiXmlBase
00357 {
00358 friend class TiXmlDocument;
00359 friend class TiXmlElement;
00360
00361 public:
00362 #ifdef TIXML_USE_STL
00363
00367 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00368
00385 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00386
00388 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00389
00390 #else
00391
00392 friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00393 #endif
00394
00398 enum NodeType
00399 {
00400 DOCUMENT,
00401 ELEMENT,
00402 COMMENT,
00403 UNKNOWN,
00404 TEXT,
00405 DECLARATION,
00406 TYPECOUNT
00407 };
00408
00409 virtual ~TiXmlNode();
00410
00423 const char * Value() const { return value.c_str (); }
00424
00434 void SetValue(const char * _value) { value = _value;}
00435
00436 #ifdef TIXML_USE_STL
00437
00438 void SetValue( const std::string& _value )
00439 {
00440 StringToBuffer buf( _value );
00441 SetValue( buf.buffer ? buf.buffer : "" );
00442 }
00443 #endif
00444
00446 void Clear();
00447
00449 TiXmlNode* Parent() const { return parent; }
00450
00451 TiXmlNode* FirstChild() const { return firstChild; }
00452 TiXmlNode* FirstChild( const char * value ) const;
00453
00454 TiXmlNode* LastChild() const { return lastChild; }
00455 TiXmlNode* LastChild( const char * value ) const;
00456
00457 #ifdef TIXML_USE_STL
00458 TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00459 TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00460 #endif
00461
00478 TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
00479
00481 TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
00482
00483 #ifdef TIXML_USE_STL
00484 TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00485 #endif
00486
00490 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00491
00492
00502 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00503
00507 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00508
00512 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00513
00517 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00518
00520 bool RemoveChild( TiXmlNode* removeThis );
00521
00523 TiXmlNode* PreviousSibling() const { return prev; }
00524
00526 TiXmlNode* PreviousSibling( const char * ) const;
00527
00528 #ifdef TIXML_USE_STL
00529 TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00530 TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00531 #endif
00532
00534 TiXmlNode* NextSibling() const { return next; }
00535
00537 TiXmlNode* NextSibling( const char * ) const;
00538
00543 TiXmlElement* NextSiblingElement() const;
00544
00549 TiXmlElement* NextSiblingElement( const char * ) const;
00550
00551 #ifdef TIXML_USE_STL
00552 TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00553 #endif
00554
00556 TiXmlElement* FirstChildElement() const;
00557
00559 TiXmlElement* FirstChildElement( const char * value ) const;
00560
00561 #ifdef TIXML_USE_STL
00562 TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00563 #endif
00564
00569 virtual int Type() const { return type; }
00570
00574 TiXmlDocument* GetDocument() const;
00575
00577 bool NoChildren() const { return !firstChild; }
00578
00579 TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
00580 TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
00581 TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
00582 TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
00583 TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
00584 TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
00585
00589 virtual TiXmlNode* Clone() const = 0;
00590
00591 protected:
00592 TiXmlNode( NodeType _type );
00593
00594
00595
00596 void CopyTo( TiXmlNode* target ) const;
00597
00598 #ifdef TIXML_USE_STL
00599
00600 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00601 #endif
00602
00603
00604 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00605
00606
00607 const TIXML_STRING& SValue() const { return value ; }
00608
00609 TiXmlNode* parent;
00610 NodeType type;
00611
00612 TiXmlNode* firstChild;
00613 TiXmlNode* lastChild;
00614
00615 TIXML_STRING value;
00616
00617 TiXmlNode* prev;
00618 TiXmlNode* next;
00619
00620 private:
00621 TiXmlNode( const TiXmlNode& );
00622 void operator=( const TiXmlNode& base );
00623 };
00624
00625
00633 class TiXmlAttribute : public TiXmlBase
00634 {
00635 friend class TiXmlAttributeSet;
00636
00637 public:
00639 TiXmlAttribute() : TiXmlBase()
00640 {
00641 document = 0;
00642 prev = next = 0;
00643 }
00644
00645 #ifdef TIXML_USE_STL
00646
00647 TiXmlAttribute( const std::string& _name, const std::string& _value )
00648 {
00649 name = _name;
00650 value = _value;
00651 document = 0;
00652 prev = next = 0;
00653 }
00654 #endif
00655
00657 TiXmlAttribute( const char * _name, const char * _value )
00658 {
00659 name = _name;
00660 value = _value;
00661 document = 0;
00662 prev = next = 0;
00663 }
00664
00665 const char* Name() const { return name.c_str (); }
00666 const char* Value() const { return value.c_str (); }
00667 const int IntValue() const;
00668 const double DoubleValue() const;
00669
00679 int QueryIntValue( int* value ) const;
00681 int QueryDoubleValue( double* value ) const;
00682
00683 void SetName( const char* _name ) { name = _name; }
00684 void SetValue( const char* _value ) { value = _value; }
00685
00686 void SetIntValue( int value );
00687 void SetDoubleValue( double value );
00688
00689 #ifdef TIXML_USE_STL
00690
00691 void SetName( const std::string& _name )
00692 {
00693 StringToBuffer buf( _name );
00694 SetName ( buf.buffer ? buf.buffer : "error" );
00695 }
00697 void SetValue( const std::string& _value )
00698 {
00699 StringToBuffer buf( _value );
00700 SetValue( buf.buffer ? buf.buffer : "error" );
00701 }
00702 #endif
00703
00705 TiXmlAttribute* Next() const;
00707 TiXmlAttribute* Previous() const;
00708
00709 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00710 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00711 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00712
00713
00714
00715
00716 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00717
00718
00719 virtual void Print( FILE* cfile, int depth ) const;
00720
00721 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00722
00723
00724 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00725
00726 private:
00727 TiXmlAttribute( const TiXmlAttribute& );
00728 void operator=( const TiXmlAttribute& base );
00729
00730 TiXmlDocument* document;
00731 TIXML_STRING name;
00732 TIXML_STRING value;
00733 TiXmlAttribute* prev;
00734 TiXmlAttribute* next;
00735 };
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750 class TiXmlAttributeSet
00751 {
00752 public:
00753 TiXmlAttributeSet();
00754 ~TiXmlAttributeSet();
00755
00756 void Add( TiXmlAttribute* attribute );
00757 void Remove( TiXmlAttribute* attribute );
00758
00759 TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00760 TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00761 TiXmlAttribute* Find( const char * name ) const;
00762
00763 private:
00764 TiXmlAttribute sentinel;
00765 };
00766
00767
00772 class TiXmlElement : public TiXmlNode
00773 {
00774 public:
00776 TiXmlElement (const char * in_value);
00777
00778 #ifdef TIXML_USE_STL
00779
00780 TiXmlElement( const std::string& _value );
00781 #endif
00782
00783 TiXmlElement( const TiXmlElement& );
00784
00785 void operator=( const TiXmlElement& base );
00786
00787 virtual ~TiXmlElement();
00788
00792 const char* Attribute( const char* name ) const;
00793
00800 const char* Attribute( const char* name, int* i ) const;
00801
00808 const char* Attribute( const char* name, double* d ) const;
00809
00817 int QueryIntAttribute( const char* name, int* value ) const;
00819 int QueryDoubleAttribute( const char* name, double* value ) const;
00820
00824 void SetAttribute( const char* name, const char * value );
00825
00826 #ifdef TIXML_USE_STL
00827 const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
00828 const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
00829 const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); }
00830 int QueryIntAttribute( const std::string& name, int* value ) const { return QueryIntAttribute( name.c_str(), value ); }
00831 int QueryDoubleAttribute( const std::string& name, double* value ) const { return QueryDoubleAttribute( name.c_str(), value ); }
00832
00834 void SetAttribute( const std::string& name, const std::string& _value )
00835 {
00836 StringToBuffer n( name );
00837 StringToBuffer v( _value );
00838 if ( n.buffer && v.buffer )
00839 SetAttribute (n.buffer, v.buffer );
00840 }
00842 void SetAttribute( const std::string& name, int _value )
00843 {
00844 StringToBuffer n( name );
00845 if ( n.buffer )
00846 SetAttribute (n.buffer, _value);
00847 }
00848 #endif
00849
00853 void SetAttribute( const char * name, int value );
00854
00858 void SetDoubleAttribute( const char * name, double value );
00859
00862 void RemoveAttribute( const char * name );
00863 #ifdef TIXML_USE_STL
00864 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
00865 #endif
00866
00867 TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
00868 TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
00869
00871 virtual TiXmlNode* Clone() const;
00872
00873 virtual void Print( FILE* cfile, int depth ) const;
00874
00875
00876
00877
00878 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00879
00880 protected:
00881
00882 void CopyTo( TiXmlElement* target ) const;
00883 void ClearThis();
00884
00885
00886 #ifdef TIXML_USE_STL
00887 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00888 #endif
00889 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00890
00891
00892
00893
00894
00895 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
00896
00897 private:
00898
00899 TiXmlAttributeSet attributeSet;
00900 };
00901
00902
00905 class TiXmlComment : public TiXmlNode
00906 {
00907 public:
00909 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
00910 TiXmlComment( const TiXmlComment& );
00911 void operator=( const TiXmlComment& base );
00912
00913 virtual ~TiXmlComment() {}
00914
00916 virtual TiXmlNode* Clone() const;
00918 virtual void Print( FILE* cfile, int depth ) const;
00919
00920
00921
00922
00923 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00924
00925 protected:
00926 void CopyTo( TiXmlComment* target ) const;
00927
00928
00929 #ifdef TIXML_USE_STL
00930 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00931 #endif
00932 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00933
00934 private:
00935
00936 };
00937
00938
00941 class TiXmlText : public TiXmlNode
00942 {
00943 friend class TiXmlElement;
00944 public:
00946 TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
00947 {
00948 SetValue( initValue );
00949 }
00950 virtual ~TiXmlText() {}
00951
00952 #ifdef TIXML_USE_STL
00953
00954 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
00955 {
00956 SetValue( initValue );
00957 }
00958 #endif
00959
00960 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
00961 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
00962
00964 virtual void Print( FILE* cfile, int depth ) const;
00965
00966 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00967
00968 protected :
00970 virtual TiXmlNode* Clone() const;
00971 void CopyTo( TiXmlText* target ) const;
00972
00973 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00974 bool Blank() const;
00975
00976 #ifdef TIXML_USE_STL
00977 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00978 #endif
00979
00980 private:
00981 };
00982
00983
00997 class TiXmlDeclaration : public TiXmlNode
00998 {
00999 public:
01001 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01002
01003 #ifdef TIXML_USE_STL
01004
01005 TiXmlDeclaration( const std::string& _version,
01006 const std::string& _encoding,
01007 const std::string& _standalone );
01008 #endif
01009
01011 TiXmlDeclaration( const char* _version,
01012 const char* _encoding,
01013 const char* _standalone );
01014
01015 TiXmlDeclaration( const TiXmlDeclaration& copy );
01016 void operator=( const TiXmlDeclaration& copy );
01017
01018 virtual ~TiXmlDeclaration() {}
01019
01021 const char *Version() const { return version.c_str (); }
01023 const char *Encoding() const { return encoding.c_str (); }
01025 const char *Standalone() const { return standalone.c_str (); }
01026
01028 virtual TiXmlNode* Clone() const;
01030 virtual void Print( FILE* cfile, int depth ) const;
01031
01032 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01033
01034 protected:
01035 void CopyTo( TiXmlDeclaration* target ) const;
01036
01037 #ifdef TIXML_USE_STL
01038 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01039 #endif
01040 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01041
01042 private:
01043
01044 TIXML_STRING version;
01045 TIXML_STRING encoding;
01046 TIXML_STRING standalone;
01047 };
01048
01049
01057 class TiXmlUnknown : public TiXmlNode
01058 {
01059 public:
01060 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01061 virtual ~TiXmlUnknown() {}
01062
01063 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01064 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01065
01067 virtual TiXmlNode* Clone() const;
01069 virtual void Print( FILE* cfile, int depth ) const;
01070
01071 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01072
01073 protected:
01074 void CopyTo( TiXmlUnknown* target ) const;
01075
01076 #ifdef TIXML_USE_STL
01077 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01078 #endif
01079 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01080
01081 private:
01082
01083 };
01084
01085
01090 class TiXmlDocument : public TiXmlNode
01091 {
01092 public:
01094 TiXmlDocument();
01096 TiXmlDocument( const char * documentName );
01097
01098 #ifdef TIXML_USE_STL
01099
01100 TiXmlDocument( const std::string& documentName );
01101 #endif
01102
01103 TiXmlDocument( const TiXmlDocument& copy );
01104 void operator=( const TiXmlDocument& copy );
01105
01106 virtual ~TiXmlDocument() {}
01107
01112 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01114 bool SaveFile() const;
01116 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01118 bool SaveFile( const char * filename ) const;
01119
01120 #ifdef TIXML_USE_STL
01121 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01122 {
01123 StringToBuffer f( filename );
01124 return ( f.buffer && LoadFile( f.buffer, encoding ));
01125 }
01126 bool SaveFile( const std::string& filename ) const
01127 {
01128 StringToBuffer f( filename );
01129 return ( f.buffer && SaveFile( f.buffer ));
01130 }
01131 #endif
01132
01137 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01138
01143 TiXmlElement* RootElement() const { return FirstChildElement(); }
01144
01150 bool Error() const { return error; }
01151
01153 const char * ErrorDesc() const { return errorDesc.c_str (); }
01154
01158 const int ErrorId() const { return errorId; }
01159
01167 int ErrorRow() { return errorLocation.row+1; }
01168 int ErrorCol() { return errorLocation.col+1; }
01169
01190 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01191
01192 int TabSize() const { return tabsize; }
01193
01197 void ClearError() { error = false;
01198 errorId = 0;
01199 errorDesc = "";
01200 errorLocation.row = errorLocation.col = 0;
01201
01202 }
01203
01205 void Print() const { Print( stdout, 0 ); }
01206
01208 virtual void Print( FILE* cfile, int depth = 0 ) const;
01209
01210 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01211
01212 protected :
01213 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01214
01215 virtual TiXmlNode* Clone() const;
01216 #ifdef TIXML_USE_STL
01217 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01218 #endif
01219
01220 private:
01221 void CopyTo( TiXmlDocument* target ) const;
01222
01223 bool error;
01224 int errorId;
01225 TIXML_STRING errorDesc;
01226 int tabsize;
01227 TiXmlCursor errorLocation;
01228 };
01229
01230
01311 class TiXmlHandle
01312 {
01313 public:
01315 TiXmlHandle( TiXmlNode* node ) { this->node = node; }
01317 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01318 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01319
01321 TiXmlHandle FirstChild() const;
01323 TiXmlHandle FirstChild( const char * value ) const;
01325 TiXmlHandle FirstChildElement() const;
01327 TiXmlHandle FirstChildElement( const char * value ) const;
01328
01332 TiXmlHandle Child( const char* value, int index ) const;
01336 TiXmlHandle Child( int index ) const;
01341 TiXmlHandle ChildElement( const char* value, int index ) const;
01346 TiXmlHandle ChildElement( int index ) const;
01347
01348 #ifdef TIXML_USE_STL
01349 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01350 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01351
01352 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01353 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01354 #endif
01355
01357 TiXmlNode* Node() const { return node; }
01359 TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01361 TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01363 TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01364
01365 private:
01366 TiXmlNode* node;
01367 };
01368
01369
01370 #endif
01371