openEmbroider  0.1
an open source embroidery software
 All Classes Functions Enumerations
tinyxml.h
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 //#include <windows.h>
47 #define TIXML_LOG OutputDebugString
48 #else
49 #define TIXML_LOG printf
50 #endif
51 
52 #ifdef TIXML_USE_STL
53  #include <string>
54  #include <iostream>
55  //#include <ostream>
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 
73 class TiXmlParsingData;
74 
75 /* Internal structure for tracking location of items
76  in the XML file.
77 */
79 {
80  TiXmlCursor() { Clear(); }
81  void Clear() { row = col = -1; }
82 
83  int row; // 0 based.
84  int col; // 0 based.
85 };
86 
87 
88 // Only used by Attribute::Query functions
89 enum
90 {
91  TIXML_SUCCESS,
92  TIXML_NO_ATTRIBUTE,
93  TIXML_WRONG_TYPE
94 };
95 
119 {
120  friend class TiXmlNode;
121  friend class TiXmlElement;
122  friend class TiXmlDocument;
123 
124 public:
125  TiXmlBase() {}
126  virtual ~TiXmlBase() {}
127 
133  virtual void Print( FILE* cfile, int depth ) const = 0;
134 
141  static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
142 
143  // Return the current white space setting.
144  static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
145 
164  int Row() const { return location.row + 1; }
165  int Column() const { return location.col + 1; }
166 
167 protected:
168  // See STL_STRING_BUG
169  // Utility class to overcome a bug.
171  {
172  public:
173  StringToBuffer( const TIXML_STRING& str );
174  ~StringToBuffer();
175  char* buffer;
176  };
177 
178  static const char* SkipWhiteSpace( const char* );
179  inline static bool IsWhiteSpace( int c ) { return ( isspace( c ) || c == '\n' || c == '\r' ); }
180 
181  virtual void StreamOut (TIXML_OSTREAM *) const = 0;
182 
183  #ifdef TIXML_USE_STL
184  static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
185  static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
186  #endif
187 
188  /* Reads an XML name into the string provided. Returns
189  a pointer just past the last character of the name,
190  or 0 if the function has an error.
191  */
192  static const char* ReadName( const char* p, TIXML_STRING* name );
193 
194  /* Reads text. Returns a pointer past the given end tag.
195  Wickedly complex options, but it keeps the (sensitive) code in one place.
196  */
197  static const char* ReadText( const char* in, // where to start
198  TIXML_STRING* text, // the string read
199  bool ignoreWhiteSpace, // whether to keep the white space
200  const char* endTag, // what ends this text
201  bool ignoreCase ); // whether to ignore case in the end tag
202 
203  virtual const char* Parse( const char* p, TiXmlParsingData* data ) = 0;
204 
205  // If an entity has been found, transform it into a character.
206  static const char* GetEntity( const char* in, char* value );
207 
208  // Get a character, while interpreting entities.
209  inline static const char* GetChar( const char* p, char* _value )
210  {
211  assert( p );
212  if ( *p == '&' )
213  {
214  return GetEntity( p, _value );
215  }
216  else
217  {
218  *_value = *p;
219  return p+1;
220  }
221  }
222 
223  // Puts a string to a stream, expanding entities as it goes.
224  // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
225  static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
226 
227  static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
228 
229  // Return true if the next characters in the stream are any of the endTag sequences.
230  static bool StringEqual( const char* p,
231  const char* endTag,
232  bool ignoreCase );
233 
234 
235  enum
236  {
237  TIXML_NO_ERROR = 0,
238  TIXML_ERROR,
239  TIXML_ERROR_OPENING_FILE,
240  TIXML_ERROR_OUT_OF_MEMORY,
241  TIXML_ERROR_PARSING_ELEMENT,
242  TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
243  TIXML_ERROR_READING_ELEMENT_VALUE,
244  TIXML_ERROR_READING_ATTRIBUTES,
245  TIXML_ERROR_PARSING_EMPTY,
246  TIXML_ERROR_READING_END_TAG,
247  TIXML_ERROR_PARSING_UNKNOWN,
248  TIXML_ERROR_PARSING_COMMENT,
249  TIXML_ERROR_PARSING_DECLARATION,
250  TIXML_ERROR_DOCUMENT_EMPTY,
251 
252  TIXML_ERROR_STRING_COUNT
253  };
254  static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
255 
256  TiXmlCursor location;
257 
258 private:
259  struct Entity
260  {
261  const char* str;
262  unsigned int strLength;
263  char chr;
264  };
265  enum
266  {
267  NUM_ENTITY = 5,
268  MAX_ENTITY_LENGTH = 6
269 
270  };
271  static Entity entity[ NUM_ENTITY ];
272  static bool condenseWhiteSpace;
273 };
274 
275 
282 class TiXmlNode : public TiXmlBase
283 {
284  friend class TiXmlDocument;
285  friend class TiXmlElement;
286 
287 public:
288  #ifdef TIXML_USE_STL
289 
293  friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
294 
311  friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
312 
313  // Appends the XML node or attribute to a std::string.
314  friend std::string& operator<< (std::string& out, const TiXmlNode& base );
315 
316  #else
317  // Used internally, not part of the public API.
318  friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
319  #endif
320 
324  enum NodeType
325  {
326  DOCUMENT,
327  ELEMENT,
328  COMMENT,
329  UNKNOWN,
330  TEXT,
331  DECLARATION,
332  TYPECOUNT
333  };
334 
335  virtual ~TiXmlNode();
336 
349  const char * Value() const { return value.c_str (); }
350 
360  void SetValue(const char * _value) { value = _value;}
361 
362  #ifdef TIXML_USE_STL
363  // STL std::string form.
364  void SetValue( const std::string& _value )
365  {
366  StringToBuffer buf( _value );
367  SetValue( buf.buffer ? buf.buffer : "" );
368  }
369  #endif
370 
371  // Delete all the children of this node. Does not affect 'this'.
372  void Clear();
373 
374  // One step up the DOM.
375  TiXmlNode* Parent() const { return parent; }
376 
377  TiXmlNode* FirstChild() const { return firstChild; }
378  TiXmlNode* FirstChild( const char * value ) const;
379 
380  TiXmlNode* LastChild() const { return lastChild; } // The last child of this node. Will be null if there are no children.
381  TiXmlNode* LastChild( const char * value ) const; // The last child of this node matching 'value'. Will be null if there are no children.
382 
383  #ifdef TIXML_USE_STL
384  TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
385  TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
386  #endif
387 
404  TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
405 
406  // This flavor of IterateChildren searches for children with a particular 'value'
407  TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
408 
409  #ifdef TIXML_USE_STL
410  TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
411  #endif
412 
416  TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
417 
418 
428  TiXmlNode* LinkEndChild( TiXmlNode* addThis );
429 
433  TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
434 
438  TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
439 
443  TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
444 
445  // Delete a child of this node.
446  bool RemoveChild( TiXmlNode* removeThis );
447 
448  // Navigate to a sibling node.
449  TiXmlNode* PreviousSibling() const { return prev; }
450 
451  // Navigate to a sibling node.
452  TiXmlNode* PreviousSibling( const char * ) const;
453 
454  #ifdef TIXML_USE_STL
455  TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
456  TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
457  #endif
458 
459  // Navigate to a sibling node.
460  TiXmlNode* NextSibling() const { return next; }
461 
462  // Navigate to a sibling node with the given 'value'.
463  TiXmlNode* NextSibling( const char * ) const;
464 
470 
475  TiXmlElement* NextSiblingElement( const char * ) const;
476 
477  #ifdef TIXML_USE_STL
478  TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
479  #endif
480 
481  // Convenience function to get through elements.
482  TiXmlElement* FirstChildElement() const;
483 
484  // Convenience function to get through elements.
485  TiXmlElement* FirstChildElement( const char * value ) const;
486 
487  #ifdef TIXML_USE_STL
488  TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
489  #endif
490 
495  virtual int Type() const { return type; }
496 
500  TiXmlDocument* GetDocument() const;
501 
502  // Returns true if this node has no children.
503  bool NoChildren() const { return !firstChild; }
504 
505  TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
506  TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
507  TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
508  TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
509  TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
510  TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
511 
512  virtual TiXmlNode* Clone() const = 0;
513 
514  void SetUserData( void* user ) { userData = user; }
515  void* GetUserData() { return userData; }
516 
517 protected:
518  TiXmlNode( NodeType type );
519 
520  #ifdef TIXML_USE_STL
521  // The real work of the input operator.
522  virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
523  #endif
524 
525  // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
526  TiXmlNode* Identify( const char* start );
527  void CopyToClone( TiXmlNode* target ) const { target->SetValue (value.c_str() );
528  target->userData = userData; }
529 
530  // Internal Value function returning a TIXML_STRING
531  TIXML_STRING SValue() const { return value ; }
532 
533  TiXmlNode* parent;
534  NodeType type;
535 
536  TiXmlNode* firstChild;
537  TiXmlNode* lastChild;
538 
539  TIXML_STRING value;
540 
541  TiXmlNode* prev;
542  TiXmlNode* next;
543  void* userData;
544 };
545 
546 
554 class TiXmlAttribute : public TiXmlBase
555 {
556  friend class TiXmlAttributeSet;
557 
558 public:
559  // Construct an empty attribute.
561  {
562  document = 0;
563  prev = next = 0;
564  }
565 
566  #ifdef TIXML_USE_STL
567  // std::string constructor.
568  TiXmlAttribute( const std::string& _name, const std::string& _value )
569  {
570  name = _name;
571  value = _value;
572  document = 0;
573  prev = next = 0;
574  }
575  #endif
576 
577  // Construct an attribute with a name and value.
578  TiXmlAttribute( const char * _name, const char * _value )
579  {
580  name = _name;
581  value = _value;
582  document = 0;
583  prev = next = 0;
584  }
585 
586  const char* Name() const { return name.c_str (); }
587  const char* Value() const { return value.c_str (); }
588  const int IntValue() const;
589  const double DoubleValue() const;
590 
600  int QueryIntValue( int* value ) const;
601  // QueryDoubleValue examines the value string. See QueryIntValue().
602  int QueryDoubleValue( double* value ) const;
603 
604  void SetName( const char* _name ) { name = _name; }
605  void SetValue( const char* _value ) { value = _value; }
606 
607  void SetIntValue( int value );
608  void SetDoubleValue( double value );
609 
610  #ifdef TIXML_USE_STL
611  // STL std::string form.
612  void SetName( const std::string& _name )
613  {
614  StringToBuffer buf( _name );
615  SetName ( buf.buffer ? buf.buffer : "error" );
616  }
617  // STL std::string form.
618  void SetValue( const std::string& _value )
619  {
620  StringToBuffer buf( _value );
621  SetValue( buf.buffer ? buf.buffer : "error" );
622  }
623  #endif
624 
625  // Get the next sibling attribute in the DOM. Returns null at end.
626  TiXmlAttribute* Next() const;
627  // Get the previous sibling attribute in the DOM. Returns null at beginning.
628  TiXmlAttribute* Previous() const;
629 
630  bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
631  bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
632  bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
633 
634  /* [internal use]
635  Attribtue parsing starts: first letter of the name
636  returns: the next char after the value end quote
637  */
638  virtual const char* Parse( const char* p, TiXmlParsingData* data );
639 
640  // [internal use]
641  virtual void Print( FILE* cfile, int depth ) const;
642 
643  virtual void StreamOut( TIXML_OSTREAM * out ) const;
644  // [internal use]
645  // Set the document pointer so the attribute can report errors.
646  void SetDocument( TiXmlDocument* doc ) { document = doc; }
647 
648 private:
649  TiXmlDocument* document; // A pointer back to a document, for error reporting.
650  TIXML_STRING name;
651  TIXML_STRING value;
652  TiXmlAttribute* prev;
653  TiXmlAttribute* next;
654 };
655 
656 
657 /* A class used to manage a group of attributes.
658  It is only used internally, both by the ELEMENT and the DECLARATION.
659 
660  The set can be changed transparent to the Element and Declaration
661  classes that use it, but NOT transparent to the Attribute
662  which has to implement a next() and previous() method. Which makes
663  it a bit problematic and prevents the use of STL.
664 
665  This version is implemented with circular lists because:
666  - I like circular lists
667  - it demonstrates some independence from the (typical) doubly linked list.
668 */
670 {
671 public:
674 
675  void Add( TiXmlAttribute* attribute );
676  void Remove( TiXmlAttribute* attribute );
677 
678  TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
679  TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
680  TiXmlAttribute* Find( const char * name ) const;
681 
682 private:
683  TiXmlAttribute sentinel;
684 };
685 
686 
691 class TiXmlElement : public TiXmlNode
692 {
693 public:
694  // Construct an element.
695  TiXmlElement (const char * in_value);
696 
697  #ifdef TIXML_USE_STL
698  // std::string constructor.
699  TiXmlElement( const std::string& _value ) : TiXmlNode( TiXmlNode::ELEMENT )
700  {
701  firstChild = lastChild = 0;
702  value = _value;
703  }
704  #endif
705 
706  virtual ~TiXmlElement();
707 
711  const char* Attribute( const char* name ) const;
712 
719  const char* Attribute( const char* name, int* i ) const;
720 
727  const char* Attribute( const char* name, double* d ) const;
728 
736  int QueryIntAttribute( const char* name, int* value ) const;
737  // QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
738  int QueryDoubleAttribute( const char* name, double* value ) const;
739 
743  void SetAttribute( const char* name, const char * value );
744 
745  #ifdef TIXML_USE_STL
746  const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
747  const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
748 
749  // STL std::string form.
750  void SetAttribute( const std::string& name, const std::string& _value )
751  {
752  StringToBuffer n( name );
753  StringToBuffer v( _value );
754  if ( n.buffer && v.buffer )
755  SetAttribute (n.buffer, v.buffer );
756  }
758  void SetAttribute( const std::string& name, int _value )
759  {
760  StringToBuffer n( name );
761  if ( n.buffer )
762  SetAttribute (n.buffer, _value);
763  }
764  #endif
765 
769  void SetAttribute( const char * name, int value );
770 
773  void RemoveAttribute( const char * name );
774  #ifdef TIXML_USE_STL
775  void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
776  #endif
777 
778  TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
779  TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
780 
781  // [internal use] Creates a new Element and returs it.
782  virtual TiXmlNode* Clone() const;
783  // [internal use]
784 
785  virtual void Print( FILE* cfile, int depth ) const;
786 
787 protected:
788 
789  // Used to be public [internal use]
790  #ifdef TIXML_USE_STL
791  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
792  #endif
793  virtual void StreamOut( TIXML_OSTREAM * out ) const;
794 
795  /* [internal use]
796  Attribtue parsing starts: next char past '<'
797  returns: next char past '>'
798  */
799  virtual const char* Parse( const char* p, TiXmlParsingData* data );
800 
801  /* [internal use]
802  Reads the "value" of the element -- another element, or text.
803  This should terminate with the current end tag.
804  */
805  const char* ReadValue( const char* in, TiXmlParsingData* prevData );
806 
807 private:
808  TiXmlAttributeSet attributeSet;
809 };
810 
811 
814 class TiXmlComment : public TiXmlNode
815 {
816 public:
817  // Constructs an empty comment.
818  TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
819  virtual ~TiXmlComment() {}
820 
821  // [internal use] Creates a new Element and returs it.
822  virtual TiXmlNode* Clone() const;
823  // [internal use]
824  virtual void Print( FILE* cfile, int depth ) const;
825 protected:
826  // used to be public
827  #ifdef TIXML_USE_STL
828  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
829  #endif
830  virtual void StreamOut( TIXML_OSTREAM * out ) const;
831  /* [internal use]
832  Attribtue parsing starts: at the ! of the !--
833  returns: next char past '>'
834  */
835  virtual const char* Parse( const char* p, TiXmlParsingData* data );
836 };
837 
838 
841 class TiXmlText : public TiXmlNode
842 {
843  friend class TiXmlElement;
844 public:
845  // Constructor.
846  TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
847  {
848  SetValue( initValue );
849  }
850  virtual ~TiXmlText() {}
851 
852  #ifdef TIXML_USE_STL
853  // Constructor.
854  TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
855  {
856  SetValue( initValue );
857  }
858  #endif
859 
860  // [internal use]
861  virtual void Print( FILE* cfile, int depth ) const;
862 
863 protected :
864  // [internal use] Creates a new Element and returns it.
865  virtual TiXmlNode* Clone() const;
866  virtual void StreamOut ( TIXML_OSTREAM * out ) const;
867  // [internal use]
868  bool Blank() const; // returns true if all white space and new lines
869  /* [internal use]
870  Attribtue parsing starts: First char of the text
871  returns: next char past '>'
872  */
873  virtual const char* Parse( const char* p, TiXmlParsingData* data );
874  // [internal use]
875  #ifdef TIXML_USE_STL
876  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
877  #endif
878 };
879 
880 
895 {
896 public:
897  // Construct an empty declaration.
898  TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
899 
900 #ifdef TIXML_USE_STL
901  // Constructor.
902  TiXmlDeclaration( const std::string& _version,
903  const std::string& _encoding,
904  const std::string& _standalone )
905  : TiXmlNode( TiXmlNode::DECLARATION )
906  {
907  version = _version;
908  encoding = _encoding;
909  standalone = _standalone;
910  }
911 #endif
912 
913  // Construct.
914  TiXmlDeclaration( const char* _version,
915  const char* _encoding,
916  const char* _standalone );
917 
918  virtual ~TiXmlDeclaration() {}
919 
920  // Version. Will return empty if none was found.
921  const char * Version() const { return version.c_str (); }
922  // Encoding. Will return empty if none was found.
923  const char * Encoding() const { return encoding.c_str (); }
924  // Is this a standalone document?
925  const char * Standalone() const { return standalone.c_str (); }
926 
927  // [internal use] Creates a new Element and returs it.
928  virtual TiXmlNode* Clone() const;
929  // [internal use]
930  virtual void Print( FILE* cfile, int depth ) const;
931 
932 protected:
933  // used to be public
934  #ifdef TIXML_USE_STL
935  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
936  #endif
937  virtual void StreamOut ( TIXML_OSTREAM * out) const;
938  // [internal use]
939  // Attribtue parsing starts: next char past '<'
940  // returns: next char past '>'
941 
942  virtual const char* Parse( const char* p, TiXmlParsingData* data );
943 
944 private:
945  TIXML_STRING version;
946  TIXML_STRING encoding;
947  TIXML_STRING standalone;
948 };
949 
950 
956 class TiXmlUnknown : public TiXmlNode
957 {
958 public:
959  TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
960  virtual ~TiXmlUnknown() {}
961 
962  // [internal use]
963  virtual TiXmlNode* Clone() const;
964  // [internal use]
965  virtual void Print( FILE* cfile, int depth ) const;
966 protected:
967  #ifdef TIXML_USE_STL
968  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
969  #endif
970  virtual void StreamOut ( TIXML_OSTREAM * out ) const;
971  /* [internal use]
972  Attribute parsing starts: First char of the text
973  returns: next char past '>'
974  */
975  virtual const char* Parse( const char* p, TiXmlParsingData* data );
976 };
977 
978 
983 class TiXmlDocument : public TiXmlNode
984 {
985 public:
986  // Create an empty document, that has no name.
987  TiXmlDocument();
988  // Create a document with a name. The name of the document is also the filename of the xml.
989  TiXmlDocument( const char * documentName );
990 
991  #ifdef TIXML_USE_STL
992  // Constructor.
993  TiXmlDocument( const std::string& documentName ) :
994  TiXmlNode( TiXmlNode::DOCUMENT )
995  {
996  value = documentName;
997  error = false;
998  }
999  #endif
1000 
1001  virtual ~TiXmlDocument() {}
1002 
1007  bool LoadFile();
1008  // Save a file using the current document value. Returns true if successful.
1009  bool SaveFile() const;
1010  // Load a file using the given filename. Returns true if successful.
1011  bool LoadFile( const char * filename );
1012  // Save a file using the given filename. Returns true if successful.
1013  bool SaveFile( const char * filename ) const;
1014 
1015  #ifdef TIXML_USE_STL
1016  bool LoadFile( const std::string& filename )
1017  {
1018  StringToBuffer f( filename );
1019  return ( f.buffer && LoadFile( f.buffer ));
1020  }
1021  bool SaveFile( const std::string& filename ) const
1022  {
1023  StringToBuffer f( filename );
1024  return ( f.buffer && SaveFile( f.buffer ));
1025  }
1026  #endif
1027 
1030  virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 );
1031 
1036  TiXmlElement* RootElement() const { return FirstChildElement(); }
1037 
1043  bool Error() const { return error; }
1044 
1045  // Contains a textual (english) description of the error if one occurs.
1046  const char * ErrorDesc() const { return errorDesc.c_str (); }
1047 
1051  const int ErrorId() const { return errorId; }
1052 
1060  int ErrorRow() { return errorLocation.row+1; }
1061  int ErrorCol() { return errorLocation.col+1; }
1062 
1083  void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
1084 
1085  int TabSize() const { return tabsize; }
1086 
1090  void ClearError() { error = false;
1091  errorId = 0;
1092  errorDesc = "";
1093  errorLocation.row = errorLocation.col = 0;
1094  //errorLocation.last = 0;
1095  }
1096 
1098  void Print() const { Print( stdout, 0 ); }
1099 
1100  // [internal use]
1101  virtual void Print( FILE* cfile, int depth = 0 ) const;
1102  // [internal use]
1103  void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData );
1104 
1105 protected :
1106  virtual void StreamOut ( TIXML_OSTREAM * out) const;
1107  // [internal use]
1108  virtual TiXmlNode* Clone() const;
1109  #ifdef TIXML_USE_STL
1110  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1111  #endif
1112 
1113 private:
1114  bool error;
1115  int errorId;
1116  TIXML_STRING errorDesc;
1117  int tabsize;
1118  TiXmlCursor errorLocation;
1119 };
1120 
1121 
1203 {
1204 public:
1205  // Create a handle from any node (at any depth of the tree.) This can be a null pointer.
1206  TiXmlHandle( TiXmlNode* node ) { this->node = node; }
1207  // Copy constructor
1208  TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
1209 
1210  // Return a handle to the first child node.
1211  TiXmlHandle FirstChild() const;
1212  // Return a handle to the first child node with the given name.
1213  TiXmlHandle FirstChild( const char * value ) const;
1214  // Return a handle to the first child element.
1215  TiXmlHandle FirstChildElement() const;
1216  // Return a handle to the first child element with the given name.
1217  TiXmlHandle FirstChildElement( const char * value ) const;
1218 
1222  TiXmlHandle Child( const char* value, int index ) const;
1226  TiXmlHandle Child( int index ) const;
1231  TiXmlHandle ChildElement( const char* value, int index ) const;
1236  TiXmlHandle ChildElement( int index ) const;
1237 
1238  #ifdef TIXML_USE_STL
1239  TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
1240  TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
1241 
1242  TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
1243  TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
1244  #endif
1245 
1246  // Return the handle as a TiXmlNode. This may return null.
1247  TiXmlNode* Node() const { return node; }
1248  // Return the handle as a TiXmlElement. This may return null.
1249  TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
1250  // Return the handle as a TiXmlText. This may return null.
1251  TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
1252 
1253 private:
1254  TiXmlNode* node;
1255 };
1256 
1257 
1258 #endif
1259 
void ClearError()
Definition: tinyxml.h:1090
virtual const char * Parse(const char *p, TiXmlParsingData *data=0)
Definition: tinyxmlparser.cpp:438
Definition: tinyxml.h:983
void SetTabSize(int _tabsize)
Definition: tinyxml.h:1083
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Definition: tinyxml.cpp:170
void SetDoubleValue(double value)
Set the value from a double.
Definition: tinyxml.cpp:890
TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:505
TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:377
NodeType
Definition: tinyxml.h:324
TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:509
bool Error() const
Definition: tinyxml.h:1043
int Column() const
See Row()
Definition: tinyxml.h:165
Definition: tinyxml.h:956
int ErrorRow()
Definition: tinyxml.h:1060
TiXmlComment * ToComment() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:507
static void SetCondenseWhiteSpace(bool condense)
Definition: tinyxml.h:141
Definition: tinyxml.h:1202
void RemoveAttribute(const char *name)
Definition: tinyxml.cpp:370
int QueryIntValue(int *value) const
Definition: tinyxml.cpp:869
Definition: tinyxml.h:78
int ErrorCol()
The column where the error occured. See ErrorRow()
Definition: tinyxml.h:1061
const char * Value() const
Definition: tinyxml.h:349
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:586
Definition: tinyxml.h:282
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:907
TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
Definition: tinyxml.h:778
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Definition: tinyxml.cpp:249
const int IntValue() const
Return the value of this attribute, converted to an integer.
Definition: tinyxml.cpp:897
virtual int Type() const
Definition: tinyxml.h:495
void SetName(const char *_name)
Set the name of this attribute.
Definition: tinyxml.h:604
TiXmlNode * IterateChildren(TiXmlNode *previous) const
Definition: tinyxml.cpp:321
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:973
Definition: tinyxml.h:554
TiXmlElement * RootElement() const
Definition: tinyxml.h:1036
Definition: tinyxml.h:118
Definition: tinyxml.h:814
Definition: tinyxmlparser.cpp:43
void SetIntValue(int value)
Set the value from an integer.
Definition: tinyxml.cpp:883
Definition: tinyxml.h:894
const double DoubleValue() const
Return the value of this attribute, converted to a double.
Definition: tinyxml.cpp:902
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:837
TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:508
TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
Definition: tinyxml.h:779
Definition: tinyxml.h:170
int QueryIntAttribute(const char *name, int *value) const
Definition: tinyxml.cpp:508
void SetAttribute(const char *name, const char *value)
Definition: tinyxml.cpp:536
const char * Attribute(const char *name) const
Definition: tinyxml.cpp:469
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:605
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Definition: tinyxml.cpp:223
TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:506
void SetValue(const char *_value)
Definition: tinyxml.h:360
Definition: tinyxml.h:841
void Print() const
Definition: tinyxml.h:1098
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:1026
virtual void Print(FILE *cfile, int depth) const =0
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Definition: tinyxml.cpp:197
TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:510
Definition: tinyxml.h:669
Definition: tinyxml.h:691
int Row() const
Definition: tinyxml.h:164
TiXmlHandle Child(const char *value, int index) const
Definition: tinyxml.cpp:1204
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:587
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:935
TiXmlDocument * GetDocument() const
Definition: tinyxml.cpp:439
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:557
const int ErrorId() const
Definition: tinyxml.h:1051
TiXmlElement * NextSiblingElement() const
Definition: tinyxml.cpp:409
TiXmlHandle ChildElement(const char *value, int index) const
Definition: tinyxml.cpp:1242
bool LoadFile()
Definition: tinyxml.cpp:677
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Definition: tinyxml.cpp:187