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( push )
00031 #pragma warning( disable : 4530 )
00032 #pragma warning( disable : 4786 )
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
00066
00067
00068
00069
00070 #define TIXML_SAFE // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
00071 #ifdef TIXML_SAFE
00072 #if defined(_MSC_VER)
00073 #define TIXML_SNPRINTF _snprintf
00074 #define TIXML_SNSCANF _snscanf
00075 #elif defined(__GNUC__)
00076 #define TIXML_SNPRINTF snprintf
00077 #define TIXML_SNSCANF snscanf
00078 #endif
00079 #endif
00080
00081 class TiXmlDocument;
00082 class TiXmlElement;
00083 class TiXmlComment;
00084 class TiXmlUnknown;
00085 class TiXmlAttribute;
00086 class TiXmlText;
00087 class TiXmlDeclaration;
00088 class TiXmlParsingData;
00089
00090 const int TIXML_MAJOR_VERSION = 2;
00091 const int TIXML_MINOR_VERSION = 4;
00092 const int TIXML_PATCH_VERSION = 0;
00093
00094
00095
00096
00097 struct TiXmlCursor
00098 {
00099 TiXmlCursor() { Clear(); }
00100 void Clear() { row = col = -1; }
00101
00102 int row;
00103 int col;
00104 };
00105
00106
00107
00108 enum
00109 {
00110 TIXML_SUCCESS,
00111 TIXML_NO_ATTRIBUTE,
00112 TIXML_WRONG_TYPE
00113 };
00114
00115
00116
00117 enum TiXmlEncoding
00118 {
00119 TIXML_ENCODING_UNKNOWN,
00120 TIXML_ENCODING_UTF8,
00121 TIXML_ENCODING_LEGACY
00122 };
00123
00124 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00125
00148 class TiXmlBase
00149 {
00150 friend class TiXmlNode;
00151 friend class TiXmlElement;
00152 friend class TiXmlDocument;
00153
00154 public:
00155 TiXmlBase() : userData(0) {}
00156 virtual ~TiXmlBase() {}
00157
00163 virtual void Print( FILE* cfile, int depth ) const = 0;
00164
00171 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00172
00174 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00175
00194 int Row() const { return location.row + 1; }
00195 int Column() const { return location.col + 1; }
00196
00197 void SetUserData( void* user ) { userData = user; }
00198 void* GetUserData() { return userData; }
00199
00200
00201
00202 static const int utf8ByteTable[256];
00203
00204 virtual const char* Parse( const char* p,
00205 TiXmlParsingData* data,
00206 TiXmlEncoding encoding ) = 0;
00207
00208 enum
00209 {
00210 TIXML_NO_ERROR = 0,
00211 TIXML_ERROR,
00212 TIXML_ERROR_OPENING_FILE,
00213 TIXML_ERROR_OUT_OF_MEMORY,
00214 TIXML_ERROR_PARSING_ELEMENT,
00215 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00216 TIXML_ERROR_READING_ELEMENT_VALUE,
00217 TIXML_ERROR_READING_ATTRIBUTES,
00218 TIXML_ERROR_PARSING_EMPTY,
00219 TIXML_ERROR_READING_END_TAG,
00220 TIXML_ERROR_PARSING_UNKNOWN,
00221 TIXML_ERROR_PARSING_COMMENT,
00222 TIXML_ERROR_PARSING_DECLARATION,
00223 TIXML_ERROR_DOCUMENT_EMPTY,
00224 TIXML_ERROR_EMBEDDED_NULL,
00225 TIXML_ERROR_PARSING_CDATA,
00226
00227 TIXML_ERROR_STRING_COUNT
00228 };
00229
00230 protected:
00231
00232
00233
00234 class StringToBuffer
00235 {
00236 public:
00237 StringToBuffer( const TIXML_STRING& str );
00238 ~StringToBuffer();
00239 char* buffer;
00240 };
00241
00242 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00243 inline static bool IsWhiteSpace( char c )
00244 {
00245 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00246 }
00247
00248 virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00249
00250 #ifdef TIXML_USE_STL
00251 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00252 static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00253 #endif
00254
00255
00256
00257
00258
00259 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00260
00261
00262
00263
00264 static const char* ReadText( const char* in,
00265 TIXML_STRING* text,
00266 bool ignoreWhiteSpace,
00267 const char* endTag,
00268 bool ignoreCase,
00269 TiXmlEncoding encoding );
00270
00271
00272 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00273
00274
00275
00276 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00277 {
00278 assert( p );
00279 if ( encoding == TIXML_ENCODING_UTF8 )
00280 {
00281 *length = utf8ByteTable[ *((unsigned char*)p) ];
00282 assert( *length >= 0 && *length < 5 );
00283 }
00284 else
00285 {
00286 *length = 1;
00287 }
00288
00289 if ( *length == 1 )
00290 {
00291 if ( *p == '&' )
00292 return GetEntity( p, _value, length, encoding );
00293 *_value = *p;
00294 return p+1;
00295 }
00296 else if ( *length )
00297 {
00298
00299
00300 for( int i=0; p[i] && i<*length; ++i ) {
00301 _value[i] = p[i];
00302 }
00303 return p + (*length);
00304 }
00305 else
00306 {
00307
00308 return 0;
00309 }
00310 }
00311
00312
00313
00314 static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00315
00316 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00317
00318
00319
00320
00321 static bool StringEqual( const char* p,
00322 const char* endTag,
00323 bool ignoreCase,
00324 TiXmlEncoding encoding );
00325
00326 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00327
00328 TiXmlCursor location;
00329
00331 void* userData;
00332
00333
00334
00335 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00336 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00337 inline static int ToLower( int v, TiXmlEncoding encoding )
00338 {
00339 if ( encoding == TIXML_ENCODING_UTF8 )
00340 {
00341 if ( v < 128 ) return tolower( v );
00342 return v;
00343 }
00344 else
00345 {
00346 return tolower( v );
00347 }
00348 }
00349 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00350
00351 private:
00352 TiXmlBase( const TiXmlBase& );
00353 void operator=( const TiXmlBase& base );
00354
00355 struct Entity
00356 {
00357 const char* str;
00358 unsigned int strLength;
00359 char chr;
00360 };
00361 enum
00362 {
00363 NUM_ENTITY = 5,
00364 MAX_ENTITY_LENGTH = 6
00365
00366 };
00367 static Entity entity[ NUM_ENTITY ];
00368 static bool condenseWhiteSpace;
00369 };
00370
00371
00378 class TiXmlNode : public TiXmlBase
00379 {
00380 friend class TiXmlDocument;
00381 friend class TiXmlElement;
00382
00383 public:
00384 #ifdef TIXML_USE_STL
00385
00389 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00390
00407 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00408
00410 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00411
00412 #else
00413
00414 friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00415 #endif
00416
00420 enum NodeType
00421 {
00422 DOCUMENT,
00423 ELEMENT,
00424 COMMENT,
00425 UNKNOWN,
00426 TEXT,
00427 DECLARATION,
00428 TYPECOUNT
00429 };
00430
00431 virtual ~TiXmlNode();
00432
00445 const char *Value() const { return value.c_str (); }
00446
00447 #ifdef TIXML_USE_STL
00448
00452 const std::string& ValueStr() const { return value; }
00453 #endif
00454
00464 void SetValue(const char * _value) { value = _value;}
00465
00466 #ifdef TIXML_USE_STL
00467
00468 void SetValue( const std::string& _value )
00469 {
00470 StringToBuffer buf( _value );
00471 SetValue( buf.buffer ? buf.buffer : "" );
00472 }
00473 #endif
00474
00476 void Clear();
00477
00479 TiXmlNode* Parent() { return parent; }
00480 const TiXmlNode* Parent() const { return parent; }
00481
00482 const TiXmlNode* FirstChild() const { return firstChild; }
00483 TiXmlNode* FirstChild() { return firstChild; }
00484 const TiXmlNode* FirstChild( const char * value ) const;
00485 TiXmlNode* FirstChild( const char * value );
00486
00487 const TiXmlNode* LastChild() const { return lastChild; }
00488 TiXmlNode* LastChild() { return lastChild; }
00489 const TiXmlNode* LastChild( const char * value ) const;
00490 TiXmlNode* LastChild( const char * value );
00491
00492 #ifdef TIXML_USE_STL
00493 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00494 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00495 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00496 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00497 #endif
00498
00515 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00516 TiXmlNode* IterateChildren( TiXmlNode* previous );
00517
00519 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00520 TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous );
00521
00522 #ifdef TIXML_USE_STL
00523 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00524 TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00525 #endif
00526
00530 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00531
00532
00542 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00543
00547 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00548
00552 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00553
00557 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00558
00560 bool RemoveChild( TiXmlNode* removeThis );
00561
00563 const TiXmlNode* PreviousSibling() const { return prev; }
00564 TiXmlNode* PreviousSibling() { return prev; }
00565
00567 const TiXmlNode* PreviousSibling( const char * ) const;
00568 TiXmlNode* PreviousSibling( const char * );
00569
00570 #ifdef TIXML_USE_STL
00571 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00572 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00573 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00574 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00575 #endif
00576
00578 const TiXmlNode* NextSibling() const { return next; }
00579 TiXmlNode* NextSibling() { return next; }
00580
00582 const TiXmlNode* NextSibling( const char * ) const;
00583 TiXmlNode* NextSibling( const char * );
00584
00589 const TiXmlElement* NextSiblingElement() const;
00590 TiXmlElement* NextSiblingElement();
00591
00596 const TiXmlElement* NextSiblingElement( const char * ) const;
00597 TiXmlElement* NextSiblingElement( const char * );
00598
00599 #ifdef TIXML_USE_STL
00600 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00601 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00602 #endif
00603
00605 const TiXmlElement* FirstChildElement() const;
00606 TiXmlElement* FirstChildElement();
00607
00609 const TiXmlElement* FirstChildElement( const char * value ) const;
00610 TiXmlElement* FirstChildElement( const char * value );
00611
00612 #ifdef TIXML_USE_STL
00613 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00614 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00615 #endif
00616
00621 virtual int Type() const { return type; }
00622
00626 const TiXmlDocument* GetDocument() const;
00627 TiXmlDocument* GetDocument();
00628
00630 bool NoChildren() const { return !firstChild; }
00631
00632 const TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (const TiXmlDocument*) this : 0; }
00633 const TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (const TiXmlElement*) this : 0; }
00634 const TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (const TiXmlComment*) this : 0; }
00635 const TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (const TiXmlUnknown*) this : 0; }
00636 const TiXmlText* ToText() const { return ( this && type == TEXT ) ? (const TiXmlText*) this : 0; }
00637 const TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (const TiXmlDeclaration*) this : 0; }
00638
00639 TiXmlDocument* ToDocument() { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
00640 TiXmlElement* ToElement() { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
00641 TiXmlComment* ToComment() { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
00642 TiXmlUnknown* ToUnknown() { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
00643 TiXmlText* ToText() { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
00644 TiXmlDeclaration* ToDeclaration() { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
00645
00649 virtual TiXmlNode* Clone() const = 0;
00650
00651 protected:
00652 TiXmlNode( NodeType _type );
00653
00654
00655
00656 void CopyTo( TiXmlNode* target ) const;
00657
00658 #ifdef TIXML_USE_STL
00659
00660 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00661 #endif
00662
00663
00664 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00665
00666 TiXmlNode* parent;
00667 NodeType type;
00668
00669 TiXmlNode* firstChild;
00670 TiXmlNode* lastChild;
00671
00672 TIXML_STRING value;
00673
00674 TiXmlNode* prev;
00675 TiXmlNode* next;
00676
00677 private:
00678 TiXmlNode( const TiXmlNode& );
00679 void operator=( const TiXmlNode& base );
00680 };
00681
00682
00690 class TiXmlAttribute : public TiXmlBase
00691 {
00692 friend class TiXmlAttributeSet;
00693
00694 public:
00696 TiXmlAttribute() : TiXmlBase()
00697 {
00698 document = 0;
00699 prev = next = 0;
00700 }
00701
00702 #ifdef TIXML_USE_STL
00703
00704 TiXmlAttribute( const std::string& _name, const std::string& _value )
00705 {
00706 name = _name;
00707 value = _value;
00708 document = 0;
00709 prev = next = 0;
00710 }
00711 #endif
00712
00714 TiXmlAttribute( const char * _name, const char * _value )
00715 {
00716 name = _name;
00717 value = _value;
00718 document = 0;
00719 prev = next = 0;
00720 }
00721
00722 const char* Name() const { return name.c_str (); }
00723 const char* Value() const { return value.c_str (); }
00724 int IntValue() const;
00725 double DoubleValue() const;
00726
00736 int QueryIntValue( int* _value ) const;
00738 int QueryDoubleValue( double* _value ) const;
00739
00740 void SetName( const char* _name ) { name = _name; }
00741 void SetValue( const char* _value ) { value = _value; }
00742
00743 void SetIntValue( int _value );
00744 void SetDoubleValue( double _value );
00745
00746 #ifdef TIXML_USE_STL
00747
00748 void SetName( const std::string& _name )
00749 {
00750 StringToBuffer buf( _name );
00751 SetName ( buf.buffer ? buf.buffer : "error" );
00752 }
00754 void SetValue( const std::string& _value )
00755 {
00756 StringToBuffer buf( _value );
00757 SetValue( buf.buffer ? buf.buffer : "error" );
00758 }
00759 #endif
00760
00762 const TiXmlAttribute* Next() const;
00763 TiXmlAttribute* Next();
00765 const TiXmlAttribute* Previous() const;
00766 TiXmlAttribute* Previous();
00767
00768 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00769 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00770 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00771
00772
00773
00774
00775 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00776
00777
00778 virtual void Print( FILE* cfile, int depth ) const;
00779
00780 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00781
00782
00783 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00784
00785 private:
00786 TiXmlAttribute( const TiXmlAttribute& );
00787 void operator=( const TiXmlAttribute& base );
00788
00789 TiXmlDocument* document;
00790 TIXML_STRING name;
00791 TIXML_STRING value;
00792 TiXmlAttribute* prev;
00793 TiXmlAttribute* next;
00794 };
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809 class TiXmlAttributeSet
00810 {
00811 public:
00812 TiXmlAttributeSet();
00813 ~TiXmlAttributeSet();
00814
00815 void Add( TiXmlAttribute* attribute );
00816 void Remove( TiXmlAttribute* attribute );
00817
00818 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00819 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00820 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00821 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00822
00823 const TiXmlAttribute* Find( const char * name ) const;
00824 TiXmlAttribute* Find( const char * name );
00825
00826 private:
00827
00828
00829 TiXmlAttributeSet( const TiXmlAttributeSet& );
00830 void operator=( const TiXmlAttributeSet& );
00831
00832 TiXmlAttribute sentinel;
00833 };
00834
00835
00840 class TiXmlElement : public TiXmlNode
00841 {
00842 public:
00844 TiXmlElement (const char * in_value);
00845
00846 #ifdef TIXML_USE_STL
00847
00848 TiXmlElement( const std::string& _value );
00849 #endif
00850
00851 TiXmlElement( const TiXmlElement& );
00852
00853 void operator=( const TiXmlElement& base );
00854
00855 virtual ~TiXmlElement();
00856
00860 const char* Attribute( const char* name ) const;
00861
00868 const char* Attribute( const char* name, int* i ) const;
00869
00876 const char* Attribute( const char* name, double* d ) const;
00877
00885 int QueryIntAttribute( const char* name, int* _value ) const;
00887 int QueryDoubleAttribute( const char* name, double* _value ) const;
00889 int QueryFloatAttribute( const char* name, float* _value ) const {
00890 double d;
00891 int result = QueryDoubleAttribute( name, &d );
00892 if ( result == TIXML_SUCCESS ) {
00893 *_value = (float)d;
00894 }
00895 return result;
00896 }
00897
00901 void SetAttribute( const char* name, const char * _value );
00902
00903 #ifdef TIXML_USE_STL
00904 const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
00905 const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
00906 const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); }
00907 int QueryIntAttribute( const std::string& name, int* _value ) const { return QueryIntAttribute( name.c_str(), _value ); }
00908 int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); }
00909
00911 void SetAttribute( const std::string& name, const std::string& _value )
00912 {
00913 StringToBuffer n( name );
00914 StringToBuffer v( _value );
00915 if ( n.buffer && v.buffer )
00916 SetAttribute (n.buffer, v.buffer );
00917 }
00919 void SetAttribute( const std::string& name, int _value )
00920 {
00921 StringToBuffer n( name );
00922 if ( n.buffer )
00923 SetAttribute (n.buffer, _value);
00924 }
00925 #endif
00926
00930 void SetAttribute( const char * name, int value );
00931
00935 void SetDoubleAttribute( const char * name, double value );
00936
00939 void RemoveAttribute( const char * name );
00940 #ifdef TIXML_USE_STL
00941 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
00942 #endif
00943
00944 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
00945 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
00946 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
00947 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
00948
00981 const char* GetText() const;
00982
00984 virtual TiXmlNode* Clone() const;
00985
00986 virtual void Print( FILE* cfile, int depth ) const;
00987
00988
00989
00990
00991 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00992
00993 protected:
00994
00995 void CopyTo( TiXmlElement* target ) const;
00996 void ClearThis();
00997
00998
00999 #ifdef TIXML_USE_STL
01000 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01001 #endif
01002 virtual void StreamOut( TIXML_OSTREAM * out ) const;
01003
01004
01005
01006
01007
01008 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01009
01010 private:
01011
01012 TiXmlAttributeSet attributeSet;
01013 };
01014
01015
01018 class TiXmlComment : public TiXmlNode
01019 {
01020 public:
01022 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01023 TiXmlComment( const TiXmlComment& );
01024 void operator=( const TiXmlComment& base );
01025
01026 virtual ~TiXmlComment() {}
01027
01029 virtual TiXmlNode* Clone() const;
01031 virtual void Print( FILE* cfile, int depth ) const;
01032
01033
01034
01035
01036 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01037
01038 protected:
01039 void CopyTo( TiXmlComment* target ) const;
01040
01041
01042 #ifdef TIXML_USE_STL
01043 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01044 #endif
01045 virtual void StreamOut( TIXML_OSTREAM * out ) const;
01046
01047 private:
01048
01049 };
01050
01051
01057 class TiXmlText : public TiXmlNode
01058 {
01059 friend class TiXmlElement;
01060 public:
01065 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01066 {
01067 SetValue( initValue );
01068 cdata = false;
01069 }
01070 virtual ~TiXmlText() {}
01071
01072 #ifdef TIXML_USE_STL
01073
01074 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01075 {
01076 SetValue( initValue );
01077 cdata = false;
01078 }
01079 #endif
01080
01081 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01082 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01083
01085 virtual void Print( FILE* cfile, int depth ) const;
01086
01088 bool CDATA() { return cdata; }
01090 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01091
01092 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01093
01094 protected :
01096 virtual TiXmlNode* Clone() const;
01097 void CopyTo( TiXmlText* target ) const;
01098
01099 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01100 bool Blank() const;
01101
01102 #ifdef TIXML_USE_STL
01103 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01104 #endif
01105
01106 private:
01107 bool cdata;
01108 };
01109
01110
01124 class TiXmlDeclaration : public TiXmlNode
01125 {
01126 public:
01128 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01129
01130 #ifdef TIXML_USE_STL
01131
01132 TiXmlDeclaration( const std::string& _version,
01133 const std::string& _encoding,
01134 const std::string& _standalone );
01135 #endif
01136
01138 TiXmlDeclaration( const char* _version,
01139 const char* _encoding,
01140 const char* _standalone );
01141
01142 TiXmlDeclaration( const TiXmlDeclaration& copy );
01143 void operator=( const TiXmlDeclaration& copy );
01144
01145 virtual ~TiXmlDeclaration() {}
01146
01148 const char *Version() const { return version.c_str (); }
01150 const char *Encoding() const { return encoding.c_str (); }
01152 const char *Standalone() const { return standalone.c_str (); }
01153
01155 virtual TiXmlNode* Clone() const;
01157 virtual void Print( FILE* cfile, int depth ) const;
01158
01159 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01160
01161 protected:
01162 void CopyTo( TiXmlDeclaration* target ) const;
01163
01164 #ifdef TIXML_USE_STL
01165 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01166 #endif
01167 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01168
01169 private:
01170
01171 TIXML_STRING version;
01172 TIXML_STRING encoding;
01173 TIXML_STRING standalone;
01174 };
01175
01176
01184 class TiXmlUnknown : public TiXmlNode
01185 {
01186 public:
01187 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01188 virtual ~TiXmlUnknown() {}
01189
01190 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01191 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01192
01194 virtual TiXmlNode* Clone() const;
01196 virtual void Print( FILE* cfile, int depth ) const;
01197
01198 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01199
01200 protected:
01201 void CopyTo( TiXmlUnknown* target ) const;
01202
01203 #ifdef TIXML_USE_STL
01204 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01205 #endif
01206 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01207
01208 private:
01209
01210 };
01211
01212
01217 class TiXmlDocument : public TiXmlNode
01218 {
01219 public:
01221 TiXmlDocument();
01223 TiXmlDocument( const char * documentName );
01224
01225 #ifdef TIXML_USE_STL
01226
01227 TiXmlDocument( const std::string& documentName );
01228 #endif
01229
01230 TiXmlDocument( const TiXmlDocument& copy );
01231 void operator=( const TiXmlDocument& copy );
01232
01233 virtual ~TiXmlDocument() {}
01234
01239 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01241 bool SaveFile() const;
01243 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01245 bool SaveFile( const char * filename ) const;
01246
01247 #ifdef TIXML_USE_STL
01248 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01249 {
01250 StringToBuffer f( filename );
01251 return ( f.buffer && LoadFile( f.buffer, encoding ));
01252 }
01253 bool SaveFile( const std::string& filename ) const
01254 {
01255 StringToBuffer f( filename );
01256 return ( f.buffer && SaveFile( f.buffer ));
01257 }
01258 #endif
01259
01264 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01265
01270 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01271 TiXmlElement* RootElement() { return FirstChildElement(); }
01272
01278 bool Error() const { return error; }
01279
01281 const char * ErrorDesc() const { return errorDesc.c_str (); }
01282
01286 int ErrorId() const { return errorId; }
01287
01295 int ErrorRow() { return errorLocation.row+1; }
01296 int ErrorCol() { return errorLocation.col+1; }
01297
01322 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01323
01324 int TabSize() const { return tabsize; }
01325
01329 void ClearError() { error = false;
01330 errorId = 0;
01331 errorDesc = "";
01332 errorLocation.row = errorLocation.col = 0;
01333
01334 }
01335
01337 void Print() const { Print( stdout, 0 ); }
01338
01340 virtual void Print( FILE* cfile, int depth = 0 ) const;
01341
01342 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01343
01344 protected :
01345 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01346
01347 virtual TiXmlNode* Clone() const;
01348 #ifdef TIXML_USE_STL
01349 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01350 #endif
01351
01352 private:
01353 void CopyTo( TiXmlDocument* target ) const;
01354
01355 bool error;
01356 int errorId;
01357 TIXML_STRING errorDesc;
01358 int tabsize;
01359 TiXmlCursor errorLocation;
01360 };
01361
01362
01443 class TiXmlHandle
01444 {
01445 public:
01447 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01449 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01450 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01451
01453 TiXmlHandle FirstChild() const;
01455 TiXmlHandle FirstChild( const char * value ) const;
01457 TiXmlHandle FirstChildElement() const;
01459 TiXmlHandle FirstChildElement( const char * value ) const;
01460
01464 TiXmlHandle Child( const char* value, int index ) const;
01468 TiXmlHandle Child( int index ) const;
01473 TiXmlHandle ChildElement( const char* value, int index ) const;
01478 TiXmlHandle ChildElement( int index ) const;
01479
01480 #ifdef TIXML_USE_STL
01481 <