sipxportlib  Version 3.3
tinyxml.h
Go to the documentation of this file.
1 /*
2 www.sourceforge.net/projects/tinyxml
3 Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
4 
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any
7 damages arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any
10 purpose, including commercial applications, and to alter it and
11 redistribute it freely, subject to the following restrictions:
12 
13 1. The origin of this software must not be misrepresented; you must
14 not claim that you wrote the original software. If you use this
15 software in a product, an acknowledgment in the product documentation
16 would be appreciated but is not required.
17 
18 2. Altered source versions must be plainly marked as such, and
19 must not be misrepresented as being the original software.
20 
21 3. This notice may not be removed or altered from any source
22 distribution.
23 */
24 
25 
26 #ifndef TINYXML_INCLUDED
27 #define TINYXML_INCLUDED
28 
29 #ifdef _MSC_VER
30 #pragma warning( disable : 4530 )
31 #pragma warning( disable : 4786 )
32 #endif
33 
34 #include <ctype.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <assert.h>
39 
40 // Help out windows:
41 #if defined( _DEBUG ) && !defined( DEBUG )
42 #define DEBUG
43 #endif
44 
45 #if defined( DEBUG ) && defined( _MSC_VER )
46 #define WIN32_LEAN_AND_MEAN
47 #include <windows.h>
48 #define TIXML_LOG OutputDebugString
49 #else
50 #define TIXML_LOG printf
51 #endif
52 
53 #ifdef TIXML_USE_STL
54  #include <string>
55  #include <iostream>
56  #define TIXML_STRING std::string
57  #define TIXML_ISTREAM std::istream
58  #define TIXML_OSTREAM std::ostream
59 #else
60  #include "tinystr.h"
61  #define TIXML_STRING TiXmlString
62  #define TIXML_OSTREAM TiXmlOutStream
63 #endif
64 
65 class TiXmlDocument;
66 class TiXmlElement;
67 class TiXmlComment;
68 class TiXmlUnknown;
69 class TiXmlAttribute;
70 class TiXmlText;
71 class TiXmlDeclaration;
72 class TiXmlParsingData;
73 
74 const int TIXML_MAJOR_VERSION = 2;
75 const int TIXML_MINOR_VERSION = 3;
76 const int TIXML_PATCH_VERSION = 4;
77 
78 /* Internal structure for tracking location of items
79  in the XML file.
80 */
82 {
83  TiXmlCursor() { Clear(); }
84  void Clear() { row = col = -1; }
85 
86  int row; // 0 based.
87  int col; // 0 based.
88 };
89 
90 
91 // Only used by Attribute::Query functions
92 enum
93 {
97 };
98 
99 
100 // Used by the parsing routines.
102 {
106 };
107 
109 
133 {
134  friend class TiXmlNode;
135  friend class TiXmlElement;
136  friend class TiXmlDocument;
137 
138 public:
139  TiXmlBase() : userData(0) {}
140  virtual ~TiXmlBase() {}
141 
147  virtual void Print( FILE* cfile, int depth ) const = 0;
148 
155  static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
156 
158  static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
159 
178  int Row() const { return location.row + 1; }
179  int Column() const { return location.col + 1; }
180 
181  void SetUserData( void* user ) { userData = user; }
182  void* GetUserData() { return userData; }
183 
184  // Table that returns, for a given lead byte, the total number of bytes
185  // in the UTF-8 sequence.
186  static const int utf8ByteTable[256];
187 
188  virtual const char* Parse( const char* p,
189  TiXmlParsingData* data,
190  TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
191 
192  enum
193  {
209 
211  };
212 
213 protected:
214 
215  // See STL_STRING_BUG
216  // Utility class to overcome a bug.
218  {
219  public:
220  StringToBuffer( const TIXML_STRING& str );
221  ~StringToBuffer();
222  char* buffer;
223  };
224 
225  static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
226  inline static bool IsWhiteSpace( char c )
227  {
228  return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
229  }
230 
231  virtual void StreamOut (TIXML_OSTREAM *) const = 0;
232 
233  #ifdef TIXML_USE_STL
234  static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
235  static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
236  #endif
237 
238  /* Reads an XML name into the string provided. Returns
239  a pointer just past the last character of the name,
240  or 0 if the function has an error.
241  */
242  static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
243 
244  /* Reads text. Returns a pointer past the given end tag.
245  Wickedly complex options, but it keeps the (sensitive) code in one place.
246  */
247  static const char* ReadText( const char* in, // where to start
248  TIXML_STRING* text, // the string read
249  bool ignoreWhiteSpace, // whether to keep the white space
250  const char* endTag, // what ends this text
251  bool ignoreCase, // whether to ignore case in the end tag
252  TiXmlEncoding encoding ); // the current encoding
253 
254  // If an entity has been found, transform it into a character.
255  static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
256 
257  // Get a character, while interpreting entities.
258  // The length can be from 0 to 4 bytes.
259  inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
260  {
261  assert( p );
262  if ( encoding == TIXML_ENCODING_UTF8 )
263  {
264  *length = utf8ByteTable[ *((unsigned char*)p) ];
265  assert( *length >= 0 && *length < 5 );
266  }
267  else
268  {
269  *length = 1;
270  }
271 
272  if ( *length == 1 )
273  {
274  if ( *p == '&' )
275  return GetEntity( p, _value, length, encoding );
276  *_value = *p;
277  return p+1;
278  }
279  else if ( *length )
280  {
281  strncpy( _value, p, *length );
282  return p + (*length);
283  }
284  else
285  {
286  // Not valid text.
287  return 0;
288  }
289  }
290 
291  // Puts a string to a stream, expanding entities as it goes.
292  // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
293  static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
294 
295  static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
296 
297  // Return true if the next characters in the stream are any of the endTag sequences.
298  // Ignore case only works for english, and should only be relied on when comparing
299  // to Engilish words: StringEqual( p, "version", true ) is fine.
300  static bool StringEqual( const char* p,
301  const char* endTag,
302  bool ignoreCase,
303  TiXmlEncoding encoding );
304 
305  static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
306 
308 
310  void* userData;
311 
312  // None of these methods are reliable for any language except English.
313  // Good for approximation, not great for accuracy.
314  static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
315  static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
316  inline static int ToLower( int v, TiXmlEncoding encoding )
317  {
318  if ( encoding == TIXML_ENCODING_UTF8 )
319  {
320  if ( v < 128 ) return tolower( v );
321  return v;
322  }
323  else
324  {
325  return tolower( v );
326  }
327  }
328  static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
329 
330 private:
331  TiXmlBase( const TiXmlBase& ); // not implemented.
332  void operator=( const TiXmlBase& base ); // not allowed.
333 
334  struct Entity
335  {
336  const char* str;
337  unsigned int strLength;
338  char chr;
339  };
340  enum
341  {
342  NUM_ENTITY = 5,
343  MAX_ENTITY_LENGTH = 6
344 
345  };
346  static Entity entity[ NUM_ENTITY ];
347  static bool condenseWhiteSpace;
348 };
349 
350 
357 class TiXmlNode : public TiXmlBase
358 {
359  friend class TiXmlDocument;
360  friend class TiXmlElement;
361 
362 public:
363  #ifdef TIXML_USE_STL
364 
368  friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
369 
386  friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
387 
389  friend std::string& operator<< (std::string& out, const TiXmlNode& base );
390 
391  #else
392  // Used internally, not part of the public API.
393  friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
394  #endif
395 
399  enum NodeType
400  {
408  };
409 
410  virtual ~TiXmlNode();
411 
424  const char * Value() const { return value.c_str (); }
425 
435  void SetValue(const char * _value) { value = _value;}
436 
437  #ifdef TIXML_USE_STL
438  void SetValue( const std::string& _value )
440  {
441  StringToBuffer buf( _value );
442  SetValue( buf.buffer ? buf.buffer : "" );
443  }
444  #endif
445 
447  void Clear();
448 
450  TiXmlNode* Parent() { return parent; }
451  const TiXmlNode* Parent() const { return parent; }
452 
453  const TiXmlNode* FirstChild() const { return firstChild; }
455  const TiXmlNode* FirstChild( const char * value ) const;
456  TiXmlNode* FirstChild( const char * value );
457 
458  const TiXmlNode* LastChild() const { return lastChild; }
460  const TiXmlNode* LastChild( const char * value ) const;
461  TiXmlNode* LastChild( const char * value );
462 
463  #ifdef TIXML_USE_STL
464  const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
465  TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
466  const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
467  TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
468  #endif
469 
486  const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
487  TiXmlNode* IterateChildren( TiXmlNode* previous );
488 
490  const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
491  TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous );
492 
493  #ifdef TIXML_USE_STL
494  const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
495  TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
496  #endif
497 
501  TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
502 
503 
513  TiXmlNode* LinkEndChild( TiXmlNode* addThis );
514 
518  TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
519 
523  TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
524 
528  TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
529 
531  bool RemoveChild( TiXmlNode* removeThis );
532 
534  const TiXmlNode* PreviousSibling() const { return prev; }
536 
538  const TiXmlNode* PreviousSibling( const char * ) const;
539  TiXmlNode* PreviousSibling( const char * );
540 
541  #ifdef TIXML_USE_STL
542  const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
543  TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
544  const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
545  TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
546  #endif
547 
549  const TiXmlNode* NextSibling() const { return next; }
550  TiXmlNode* NextSibling() { return next; }
551 
553  const TiXmlNode* NextSibling( const char * ) const;
554  TiXmlNode* NextSibling( const char * );
555 
560  const TiXmlElement* NextSiblingElement() const;
562 
567  const TiXmlElement* NextSiblingElement( const char * ) const;
568  TiXmlElement* NextSiblingElement( const char * );
569 
570  #ifdef TIXML_USE_STL
571  const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
572  TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
573  #endif
574 
576  const TiXmlElement* FirstChildElement() const;
578 
580  const TiXmlElement* FirstChildElement( const char * value ) const;
581  TiXmlElement* FirstChildElement( const char * value );
582 
583  #ifdef TIXML_USE_STL
584  const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
585  TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
586  #endif
587 
592  virtual int Type() const { return type; }
593 
597  const TiXmlDocument* GetDocument() const;
599 
601  bool NoChildren() const { return !firstChild; }
602 
603  const TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (const TiXmlDocument*) this : 0; }
604  const TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (const TiXmlElement*) this : 0; }
605  const TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (const TiXmlComment*) this : 0; }
606  const TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (const TiXmlUnknown*) this : 0; }
607  const TiXmlText* ToText() const { return ( this && type == TEXT ) ? (const TiXmlText*) this : 0; }
608  const TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (const TiXmlDeclaration*) this : 0; }
609 
610  TiXmlDocument* ToDocument() { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
611  TiXmlElement* ToElement() { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
612  TiXmlComment* ToComment() { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
613  TiXmlUnknown* ToUnknown() { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
614  TiXmlText* ToText() { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
615  TiXmlDeclaration* ToDeclaration() { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
616 
620  virtual TiXmlNode* Clone() const = 0;
621 
622 protected:
623  TiXmlNode( NodeType _type );
624 
625  // Copy to the allocated object. Shared functionality between Clone, Copy constructor,
626  // and the assignment operator.
627  void CopyTo( TiXmlNode* target ) const;
628 
629  #ifdef TIXML_USE_STL
630  // The real work of the input operator.
631  virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
632  #endif
633 
634  // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
635  TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
636 
637  // Internal Value function returning a TIXML_STRING
638  const TIXML_STRING& SValue() const { return value ; }
639 
642 
645 
647 
650 
651 private:
652  TiXmlNode( const TiXmlNode& ); // not implemented.
653  void operator=( const TiXmlNode& base ); // not allowed.
654 };
655 
656 
664 class TiXmlAttribute : public TiXmlBase
665 {
666  friend class TiXmlAttributeSet;
667 
668 public:
671  {
672  document = 0;
673  prev = next = 0;
674  }
675 
676  #ifdef TIXML_USE_STL
677  TiXmlAttribute( const std::string& _name, const std::string& _value )
679  {
680  name = _name;
681  value = _value;
682  document = 0;
683  prev = next = 0;
684  }
685  #endif
686 
688  TiXmlAttribute( const char * _name, const char * _value )
689  {
690  name = _name;
691  value = _value;
692  document = 0;
693  prev = next = 0;
694  }
695 
696  const char* Name() const { return name.c_str (); }
697  const char* Value() const { return value.c_str (); }
698  const int IntValue() const;
699  const double DoubleValue() const;
700 
710  int QueryIntValue( int* value ) const;
712  int QueryDoubleValue( double* value ) const;
713 
714  void SetName( const char* _name ) { name = _name; }
715  void SetValue( const char* _value ) { value = _value; }
716 
717  void SetIntValue( int value );
718  void SetDoubleValue( double value );
719 
720  #ifdef TIXML_USE_STL
721  void SetName( const std::string& _name )
723  {
724  StringToBuffer buf( _name );
725  SetName ( buf.buffer ? buf.buffer : "error" );
726  }
728  void SetValue( const std::string& _value )
729  {
730  StringToBuffer buf( _value );
731  SetValue( buf.buffer ? buf.buffer : "error" );
732  }
733  #endif
734 
736  const TiXmlAttribute* Next() const;
737  TiXmlAttribute* Next();
739  const TiXmlAttribute* Previous() const;
740  TiXmlAttribute* Previous();
741 
742  bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
743  bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
744  bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
745 
746  /* Attribute parsing starts: first letter of the name
747  returns: the next char after the value end quote
748  */
749  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
750 
751  // Prints this Attribute to a FILE stream.
752  virtual void Print( FILE* cfile, int depth ) const;
753 
754  virtual void StreamOut( TIXML_OSTREAM * out ) const;
755  // [internal use]
756  // Set the document pointer so the attribute can report errors.
757  void SetDocument( TiXmlDocument* doc ) { document = doc; }
758 
759 private:
760  TiXmlAttribute( const TiXmlAttribute& ); // not implemented.
761  void operator=( const TiXmlAttribute& base ); // not allowed.
762 
763  TiXmlDocument* document; // A pointer back to a document, for error reporting.
764  TIXML_STRING name;
765  TIXML_STRING value;
766  TiXmlAttribute* prev;
767  TiXmlAttribute* next;
768 };
769 
770 
771 /* A class used to manage a group of attributes.
772  It is only used internally, both by the ELEMENT and the DECLARATION.
773 
774  The set can be changed transparent to the Element and Declaration
775  classes that use it, but NOT transparent to the Attribute
776  which has to implement a next() and previous() method. Which makes
777  it a bit problematic and prevents the use of STL.
778 
779  This version is implemented with circular lists because:
780  - I like circular lists
781  - it demonstrates some independence from the (typical) doubly linked list.
782 */
784 {
785 public:
788 
789  void Add( TiXmlAttribute* attribute );
790  void Remove( TiXmlAttribute* attribute );
791 
792  const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
793  TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
794  const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
795  TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
796 
797  const TiXmlAttribute* Find( const char * name ) const;
798  TiXmlAttribute* Find( const char * name );
799 
800 private:
801  //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
802  //*ME: this class must be also use a hidden/disabled copy-constructor !!!
803  TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed
804  void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute)
805 
806  TiXmlAttribute sentinel;
807 };
808 
809 
814 class TiXmlElement : public TiXmlNode
815 {
816 public:
818  TiXmlElement (const char * in_value);
819 
820  #ifdef TIXML_USE_STL
821  TiXmlElement( const std::string& _value );
823  #endif
824 
825  TiXmlElement( const TiXmlElement& );
826 
827  void operator=( const TiXmlElement& base );
828 
829  virtual ~TiXmlElement();
830 
834  const char* Attribute( const char* name ) const;
835 
842  const char* Attribute( const char* name, int* i ) const;
843 
850  const char* Attribute( const char* name, double* d ) const;
851 
859  int QueryIntAttribute( const char* name, int* value ) const;
861  int QueryDoubleAttribute( const char* name, double* value ) const;
863  int QueryDoubleAttribute( const char* name, float* value ) const {
864  double d;
865  int result = QueryDoubleAttribute( name, &d );
866  *value = (float)d;
867  return result;
868  }
869 
873  void SetAttribute( const char* name, const char * value );
874 
875  #ifdef TIXML_USE_STL
876  const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
877  const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
878  const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); }
879  int QueryIntAttribute( const std::string& name, int* value ) const { return QueryIntAttribute( name.c_str(), value ); }
880  int QueryDoubleAttribute( const std::string& name, double* value ) const { return QueryDoubleAttribute( name.c_str(), value ); }
881 
883  void SetAttribute( const std::string& name, const std::string& _value )
884  {
885  StringToBuffer n( name );
886  StringToBuffer v( _value );
887  if ( n.buffer && v.buffer )
888  SetAttribute (n.buffer, v.buffer );
889  }
891  void SetAttribute( const std::string& name, int _value )
892  {
893  StringToBuffer n( name );
894  if ( n.buffer )
895  SetAttribute (n.buffer, _value);
896  }
897  #endif
898 
902  void SetAttribute( const char * name, int value );
903 
907  void SetDoubleAttribute( const char * name, double value );
908 
911  void RemoveAttribute( const char * name );
912  #ifdef TIXML_USE_STL
913  void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
914  #endif
915 
916  const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
917  TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
918  const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
919  TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
920 
922  virtual TiXmlNode* Clone() const;
923  // Print the Element to a FILE stream.
924  virtual void Print( FILE* cfile, int depth ) const;
925 
926  /* Attribtue parsing starts: next char past '<'
927  returns: next char past '>'
928  */
929  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
930 
931 protected:
932 
933  void CopyTo( TiXmlElement* target ) const;
934  void ClearThis(); // like clear, but initializes 'this' object as well
935 
936  // Used to be public [internal use]
937  #ifdef TIXML_USE_STL
938  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
939  #endif
940  virtual void StreamOut( TIXML_OSTREAM * out ) const;
941 
942  /* [internal use]
943  Reads the "value" of the element -- another element, or text.
944  This should terminate with the current end tag.
945  */
946  const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
947 
948 private:
949 
950  TiXmlAttributeSet attributeSet;
951 };
952 
953 
956 class TiXmlComment : public TiXmlNode
957 {
958 public:
960  TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
961  TiXmlComment( const TiXmlComment& );
962  void operator=( const TiXmlComment& base );
963 
964  virtual ~TiXmlComment() {}
965 
967  virtual TiXmlNode* Clone() const;
969  virtual void Print( FILE* cfile, int depth ) const;
970 
971  /* Attribtue parsing starts: at the ! of the !--
972  returns: next char past '>'
973  */
974  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
975 
976 protected:
977  void CopyTo( TiXmlComment* target ) const;
978 
979  // used to be public
980  #ifdef TIXML_USE_STL
981  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
982  #endif
983  virtual void StreamOut( TIXML_OSTREAM * out ) const;
984 
985 private:
986 
987 };
988 
989 
992 class TiXmlText : public TiXmlNode
993 {
994  friend class TiXmlElement;
995 public:
997  TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
998  {
999  SetValue( initValue );
1000  }
1001  virtual ~TiXmlText() {}
1002 
1003  #ifdef TIXML_USE_STL
1004  TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
1006  {
1007  SetValue( initValue );
1008  }
1009  #endif
1010 
1011  TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
1012  void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
1013 
1015  virtual void Print( FILE* cfile, int depth ) const;
1016 
1017  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1018 
1019 protected :
1021  virtual TiXmlNode* Clone() const;
1022  void CopyTo( TiXmlText* target ) const;
1023 
1024  virtual void StreamOut ( TIXML_OSTREAM * out ) const;
1025  bool Blank() const; // returns true if all white space and new lines
1026  // [internal use]
1027  #ifdef TIXML_USE_STL
1028  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1029  #endif
1030 
1031 private:
1032 };
1033 
1034 
1049 {
1050 public:
1052  TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
1053 
1054 #ifdef TIXML_USE_STL
1055  TiXmlDeclaration( const std::string& _version,
1057  const std::string& _encoding,
1058  const std::string& _standalone );
1059 #endif
1060 
1062  TiXmlDeclaration( const char* _version,
1063  const char* _encoding,
1064  const char* _standalone );
1065 
1066  TiXmlDeclaration( const TiXmlDeclaration& copy );
1067  void operator=( const TiXmlDeclaration& copy );
1068 
1069  virtual ~TiXmlDeclaration() {}
1070 
1072  const char *Version() const { return version.c_str (); }
1074  const char *Encoding() const { return encoding.c_str (); }
1076  const char *Standalone() const { return standalone.c_str (); }
1077 
1079  virtual TiXmlNode* Clone() const;
1081  virtual void Print( FILE* cfile, int depth ) const;
1082 
1083  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1084 
1085 protected:
1086  void CopyTo( TiXmlDeclaration* target ) const;
1087  // used to be public
1088  #ifdef TIXML_USE_STL
1089  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1090  #endif
1091  virtual void StreamOut ( TIXML_OSTREAM * out) const;
1092 
1093 private:
1094 
1095  TIXML_STRING version;
1096  TIXML_STRING encoding;
1097  TIXML_STRING standalone;
1098 };
1099 
1100 
1108 class TiXmlUnknown : public TiXmlNode
1109 {
1110 public:
1111  TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
1112  virtual ~TiXmlUnknown() {}
1113 
1114  TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
1115  void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
1116 
1118  virtual TiXmlNode* Clone() const;
1120  virtual void Print( FILE* cfile, int depth ) const;
1121 
1122  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1123 
1124 protected:
1125  void CopyTo( TiXmlUnknown* target ) const;
1126 
1127  #ifdef TIXML_USE_STL
1128  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1129  #endif
1130  virtual void StreamOut ( TIXML_OSTREAM * out ) const;
1131 
1132 private:
1133 
1134 };
1135 
1136 
1141 class TiXmlDocument : public TiXmlNode
1142 {
1143 public:
1145  TiXmlDocument();
1147  TiXmlDocument( const char * documentName );
1148 
1149  #ifdef TIXML_USE_STL
1150  TiXmlDocument( const std::string& documentName );
1152  #endif
1153 
1154  TiXmlDocument( const TiXmlDocument& copy );
1155  void operator=( const TiXmlDocument& copy );
1156 
1157  virtual ~TiXmlDocument() {}
1158 
1163  bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1165  bool SaveFile() const;
1167  bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1169  bool SaveFile( const char * filename ) const;
1170 
1171  #ifdef TIXML_USE_STL
1172  bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
1173  {
1174  StringToBuffer f( filename );
1175  return ( f.buffer && LoadFile( f.buffer, encoding ));
1176  }
1177  bool SaveFile( const std::string& filename ) const
1178  {
1179  StringToBuffer f( filename );
1180  return ( f.buffer && SaveFile( f.buffer ));
1181  }
1182  #endif
1183 
1188  virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1189 
1194  const TiXmlElement* RootElement() const { return FirstChildElement(); }
1195  TiXmlElement* RootElement() { return FirstChildElement(); }
1196 
1202  bool Error() const { return error; }
1203 
1205  const char * ErrorDesc() const { return errorDesc.c_str (); }
1206 
1210  const int ErrorId() const { return errorId; }
1211 
1219  int ErrorRow() { return errorLocation.row+1; }
1220  int ErrorCol() { return errorLocation.col+1; }
1221 
1242  void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
1243 
1244  int TabSize() const { return tabsize; }
1245 
1249  void ClearError() { error = false;
1250  errorId = 0;
1251  errorDesc = "";
1252  errorLocation.row = errorLocation.col = 0;
1253  //errorLocation.last = 0;
1254  }
1255 
1257  void Print() const { Print( stdout, 0 ); }
1258 
1260  virtual void Print( FILE* cfile, int depth = 0 ) const;
1261  // [internal use]
1262  void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1263 
1264 protected :
1265  virtual void StreamOut ( TIXML_OSTREAM * out) const;
1266  // [internal use]
1267  virtual TiXmlNode* Clone() const;
1268  #ifdef TIXML_USE_STL
1269  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1270  #endif
1271 
1272 private:
1273  void CopyTo( TiXmlDocument* target ) const;
1274 
1275  bool error;
1276  int errorId;
1277  TIXML_STRING errorDesc;
1278  int tabsize;
1279  TiXmlCursor errorLocation;
1280 };
1281 
1282 
1364 {
1365 public:
1367  TiXmlHandle( TiXmlNode* node ) { this->node = node; }
1369  TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
1370  TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
1371 
1373  TiXmlHandle FirstChild() const;
1375  TiXmlHandle FirstChild( const char * value ) const;
1377  TiXmlHandle FirstChildElement() const;
1379  TiXmlHandle FirstChildElement( const char * value ) const;
1380 
1384  TiXmlHandle Child( const char* value, int index ) const;
1388  TiXmlHandle Child( int index ) const;
1393  TiXmlHandle ChildElement( const char* value, int index ) const;
1398  TiXmlHandle ChildElement( int index ) const;
1399 
1400  #ifdef TIXML_USE_STL
1401  TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
1402  TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
1403 
1404  TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
1405  TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
1406  #endif
1407 
1409  TiXmlNode* Node() const { return node; }
1411  TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
1413  TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
1415  TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
1416 
1417 private:
1418  TiXmlNode* node;
1419 };
1420 
1421 #ifdef _MSC_VER
1422 #pragma warning( default : 4530 )
1423 #pragma warning( default : 4786 )
1424 #endif
1425 
1426 #endif
1427 
const int ErrorId() const
Definition: tinyxml.h:1210
TiXmlNode * NextSibling()
Definition: tinyxml.h:550
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:697
virtual ~TiXmlComment()
Definition: tinyxml.h:964
bool operator>(const TiXmlAttribute &rhs) const
Definition: tinyxml.h:744
Definition: tinyxml.h:1141
TiXmlNode * Node() const
Return the handle as a TiXmlNode. This may return null.
Definition: tinyxml.h:1409
const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:605
TiXmlElement * RootElement()
Definition: tinyxml.h:1195
const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:608
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
Definition: tinyxml.h:1369
const TiXmlAttribute * First() const
Definition: tinyxml.h:792
const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:606
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
Definition: tinyxml.h:688
int row
Definition: tinyxml.h:86
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cpp:477
void Print() const
Definition: tinyxml.h:1257
int Column() const
See Row()
Definition: tinyxml.h:179
TiXmlText * Text() const
Return the handle as a TiXmlText. This may return null.
Definition: tinyxml.h:1413
int col
Definition: tinyxml.h:87
TiXmlNode * FirstChild()
Definition: tinyxml.h:454
int QueryDoubleAttribute(const char *name, float *value) const
QueryFloatAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.h:863
TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:615
Definition: tinyxml.h:197
void SetUserData(void *user)
Definition: tinyxml.h:181
TiXmlCursor location
Definition: tinyxml.h:307
Definition: tinyxml.h:403
Definition: tinyxml.h:194
const TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:607
Definition: tinyxml.h:202
Definition: tinyxml.h:94
Definition: tinyxml.h:1108
const char * Value() const
Definition: tinyxml.h:424
static const int utf8ByteTable[256]
Definition: tinyxml.h:186
TiXmlNode * Parent()
One step up the DOM.
Definition: tinyxml.h:450
virtual ~TiXmlBase()
Definition: tinyxml.h:140
Definition: tinyxml.h:1363
TiXmlCursor()
Definition: tinyxml.h:83
TiXmlUnknown * Unknown() const
Return the handle as a TiXmlUnknown. This may return null;.
Definition: tinyxml.h:1415
TiXmlText * ToText()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:614
TIXML_OSTREAM & operator<<(TIXML_OSTREAM &out, const TiXmlNode &base)
Definition: tinyxml.cpp:1482
Definition: tinyxml.h:406
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:696
Definition: tinyxml.h:208
TiXmlHandle(TiXmlNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml.h:1367
bool Error() const
Definition: tinyxml.h:1202
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml.h:601
const int TIXML_PATCH_VERSION
Definition: tinyxml.h:76
const TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
Definition: tinyxml.h:918
TiXmlDeclaration()
Construct an empty declaration.
Definition: tinyxml.h:1052
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
Definition: tinyxml.h:158
Definition: tinyxml.h:405
Definition: tinyxml.h:81
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Definition: tinyxml.cpp:213
TiXmlElement * Element() const
Return the handle as a TiXmlElement. This may return null.
Definition: tinyxml.h:1411
const TiXmlNode * Parent() const
Definition: tinyxml.h:451
Definition: tinyxml.h:196
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition: tinyxml.h:1205
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
Definition: tinyxml.cpp:866
Definition: tinyxml.h:103
void CopyTo(TiXmlText *target) const
Definition: tinyxml.cpp:1252
virtual ~TiXmlText()
Definition: tinyxml.h:1001
Definition: tinyxml.h:357
static void SetCondenseWhiteSpace(bool condense)
Definition: tinyxml.h:155
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:761
void CopyTo(TiXmlElement *target) const
Definition: tinyxml.cpp:843
const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:604
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Definition: tinyxml.cpp:223
virtual ~TiXmlUnknown()
Definition: tinyxml.h:1112
Definition: tinyxml.h:96
TiXmlAttribute * LastAttribute()
Definition: tinyxml.h:919
TiXmlNode * lastChild
Definition: tinyxml.h:644
#define TIXML_OSTREAM
Definition: tinyxml.h:62
Definition: tinyxml.h:104
int ErrorRow()
Definition: tinyxml.h:1219
const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:603
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:534
const TiXmlEncoding TIXML_DEFAULT_ENCODING
Definition: tinyxml.h:108
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:549
static int ToLower(int v, TiXmlEncoding encoding)
Definition: tinyxml.h:316
const TiXmlNode * LastChild() const
Definition: tinyxml.h:458
static bool IsWhiteSpace(char c)
Definition: tinyxml.h:226
Definition: tinyxml.h:664
virtual void StreamOut(TIXML_OSTREAM *out) const
Definition: tinyxml.cpp:812
const int TIXML_MAJOR_VERSION
Definition: tinyxml.h:74
void CopyTo(TiXmlUnknown *target) const
Definition: tinyxml.cpp:1384
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Definition: tinyxml.cpp:196
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:797
virtual ~TiXmlNode()
Definition: tinyxml.cpp:158
Definition: tinyxml.h:401
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Definition: tinyxml.cpp:275
Definition: tinyxml.h:132
Definition: tinyxml.h:956
Definition: tinyxmlparser.cpp:162
Definition: tinyxml.h:1048
TiXmlNode * LastChild()
The last child of this node. Will be null if there are no children.
Definition: tinyxml.h:459
virtual ~TiXmlDeclaration()
Definition: tinyxml.h:1069
TiXmlAttribute * FirstAttribute()
Definition: tinyxml.h:917
TiXmlText(const TiXmlText &copy)
Definition: tinyxml.h:1011
TiXmlEncoding
Definition: tinyxml.h:101
void operator=(const TiXmlText &base)
Definition: tinyxml.h:1012
const char * Encoding() const
Encoding. Will return an empty string if none was found.
Definition: tinyxml.h:1074
Definition: tinyxml.h:217
TiXmlBase()
Definition: tinyxml.h:139
const TiXmlElement * RootElement() const
Definition: tinyxml.h:1194
void SetName(const char *_name)
Set the name of this attribute.
Definition: tinyxml.h:714
bool operator==(const TiXmlAttribute &rhs) const
Definition: tinyxml.h:742
Definition: tinyxml.h:195
void SetDocument(TiXmlDocument *doc)
Definition: tinyxml.h:757
Definition: tinyxml.h:407
TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:613
void operator=(const TiXmlElement &base)
Definition: tinyxml.cpp:640
bool operator<(const TiXmlAttribute &rhs) const
Definition: tinyxml.h:743
TiXmlAttribute()
Construct an empty attribute.
Definition: tinyxml.h:670
TiXmlHandle operator=(const TiXmlHandle &ref)
Definition: tinyxml.h:1370
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:453
static const char * GetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)
Definition: tinyxml.h:259
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
Definition: tinyxml.cpp:303
#define assert(exp)
Definition: WinCEFixups.h:37
void ClearError()
Definition: tinyxml.h:1249
Definition: tinyxml.h:207
NodeType
Definition: tinyxml.h:399
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Definition: tinyxml.cpp:249
void * GetUserData()
Definition: tinyxml.h:182
Definition: tinyxml.h:992
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxmlparser.cpp:683
Definition: tinyxml.h:404
char * buffer
Definition: tinyxml.h:222
const TiXmlDocument * GetDocument() const
Definition: tinyxml.cpp:590
TiXmlAttribute * Last()
Definition: tinyxml.h:795
void Clear()
Definition: tinyxml.h:84
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:715
Definition: tinyxml.h:402
virtual int Type() const
Definition: tinyxml.h:592
TiXmlNode * next
Definition: tinyxml.h:649
virtual ~TiXmlDocument()
Definition: tinyxml.h:1157
TiXmlNode * firstChild
Definition: tinyxml.h:643
Definition: tinyxml.h:783
Definition: tinyxml.h:814
NodeType type
Definition: tinyxml.h:641
TiXmlNode(NodeType _type)
Definition: tinyxml.cpp:147
int TabSize() const
Definition: tinyxml.h:1244
const TiXmlElement * NextSiblingElement() const
Definition: tinyxml.cpp:533
void operator=(const TiXmlUnknown &copy)
Definition: tinyxml.h:1115
TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:610
TiXmlNode * parent
Definition: tinyxml.h:640
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
Definition: tinyxml.cpp:371
const char * Version() const
Version. Will return an empty string if none was found.
Definition: tinyxml.h:1072
const TIXML_STRING & SValue() const
Definition: tinyxml.h:638
TiXmlText(const char *initValue)
Constructor.
Definition: tinyxml.h:997
TiXmlElement * ToElement()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:611
TiXmlComment * ToComment()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:612
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
Definition: tinyxml.h:916
void * userData
Field containing a generic user pointer.
Definition: tinyxml.h:310
int ErrorCol()
The column where the error occured. See ErrorRow()
Definition: tinyxml.h:1220
TIXML_STRING value
Definition: tinyxml.h:646
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:1006
TiXmlUnknown()
Definition: tinyxml.h:1111
TiXmlNode * PreviousSibling()
Definition: tinyxml.h:535
const TiXmlAttribute * Last() const
Definition: tinyxml.h:794
int Row() const
Definition: tinyxml.h:178
void SetValue(const char *_value)
Definition: tinyxml.h:435
void SetTabSize(int _tabsize)
Definition: tinyxml.h:1242
const char * Standalone() const
Is this a standalone document?
Definition: tinyxml.h:1076
TiXmlUnknown(const TiXmlUnknown &copy)
Definition: tinyxml.h:1114
Definition: tinyxml.h:95
Definition: tinyxml.h:210
#define TIXML_STRING
Definition: tinyxml.h:61
const int TIXML_MINOR_VERSION
Definition: tinyxml.h:75
TiXmlAttribute * First()
Definition: tinyxml.h:793
TiXmlComment()
Constructs an empty comment.
Definition: tinyxml.h:960
TiXmlNode * prev
Definition: tinyxml.h:648
Definition: tinyxml.h:105