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