TDME2  1.9.200
tinyxml.h
Go to the documentation of this file.
1 /*
2 www.sourceforge.net/projects/tinyxml
3 Original code by 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 #pragma once
26 
27 #include <assert.h>
28 #include <ctype.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 
33 #include <string>
34 #include <iostream>
35 #include <sstream>
36 #define TIXML_STRING std::string
37 
38 // Deprecated library function hell. Compilers want to use the
39 // new safe versions. This probably doesn't fully address the problem,
40 // but it gets closer. There are too many compilers for me to fully
41 // test. If you get compilation troubles, undefine TIXML_SAFE
42 #define TIXML_SAFE
43 
44 #ifdef TIXML_SAFE
45  #if defined(__GNUC__) && (__GNUC__ >= 3 )
46  // GCC version 3 and higher.s
47  //#warning( "Using sn* functions." )
48  #define TIXML_SNPRINTF snprintf
49  #define TIXML_SSCANF sscanf
50  #else
51  #define TIXML_SNPRINTF snprintf
52  #define TIXML_SSCANF sscanf
53  #endif
54 #endif
55 
56 namespace tinyxml {
57 
58  class TiXmlDocument;
59  class TiXmlElement;
60  class TiXmlComment;
61  class TiXmlUnknown;
62  class TiXmlAttribute;
63  class TiXmlText;
64  class TiXmlDeclaration;
65  class TiXmlParsingData;
66 
67  const int TIXML_MAJOR_VERSION = 2;
68  const int TIXML_MINOR_VERSION = 6;
69  const int TIXML_PATCH_VERSION = 2;
70 
71  /* Internal structure for tracking location of items
72  in the XML file.
73  */
74  struct TiXmlCursor
75  {
76  TiXmlCursor() { Clear(); }
77  void Clear() { row = col = -1; }
78 
79  int row; // 0 based.
80  int col; // 0 based.
81  };
82 
83 
84  /**
85  Implements the interface to the "Visitor pattern" (see the Accept() method.)
86  If you call the Accept() method, it requires being passed a TiXmlVisitor
87  class to handle callbacks. For nodes that contain other nodes (Document, Element)
88  you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves
89  are simply called with Visit().
90 
91  If you return 'true' from a Visit method, recursive parsing will continue. If you return
92  false, <b>no children of this node or its sibilings</b> will be Visited.
93 
94  All flavors of Visit methods have a default implementation that returns 'true' (continue
95  visiting). You need to only override methods that are interesting to you.
96 
97  Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting.
98 
99  You should never change the document from a callback.
100 
101  @sa TiXmlNode::Accept()
102  */
104  {
105  public:
106  virtual ~TiXmlVisitor() {}
107 
108  /// Visit a document.
109  virtual bool VisitEnter( const TiXmlDocument& /*doc*/ ) { return true; }
110  /// Visit a document.
111  virtual bool VisitExit( const TiXmlDocument& /*doc*/ ) { return true; }
112 
113  /// Visit an element.
114  virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ ) { return true; }
115  /// Visit an element.
116  virtual bool VisitExit( const TiXmlElement& /*element*/ ) { return true; }
117 
118  /// Visit a declaration
119  virtual bool Visit( const TiXmlDeclaration& /*declaration*/ ) { return true; }
120  /// Visit a text node
121  virtual bool Visit( const TiXmlText& /*text*/ ) { return true; }
122  /// Visit a comment node
123  virtual bool Visit( const TiXmlComment& /*comment*/ ) { return true; }
124  /// Visit an unknown node
125  virtual bool Visit( const TiXmlUnknown& /*unknown*/ ) { return true; }
126  };
127 
128  // Only used by Attribute::Query functions
129  enum
130  {
134  };
135 
136 
137  // Used by the parsing routines.
139  {
143  };
144 
146 
147  /** TiXmlBase is a base class for every class in TinyXml.
148  It does little except to establish that TinyXml classes
149  can be printed and provide some utility functions.
150 
151  In XML, the document and elements can contain
152  other elements and other types of nodes.
153 
154  @verbatim
155  A Document can contain: Element (container or leaf)
156  Comment (leaf)
157  Unknown (leaf)
158  Declaration( leaf )
159 
160  An Element can contain: Element (container or leaf)
161  Text (leaf)
162  Attributes (not on tree)
163  Comment (leaf)
164  Unknown (leaf)
165 
166  A Decleration contains: Attributes (not on tree)
167  @endverbatim
168  */
169  class TiXmlBase
170  {
171  friend class TiXmlNode;
172  friend class TiXmlElement;
173  friend class TiXmlDocument;
174 
175  public:
176  TiXmlBase() : userData(0) {}
177  virtual ~TiXmlBase() {}
178 
179  /** All TinyXml classes can print themselves to a filestream
180  or the string class (TiXmlString in non-STL mode, std::string
181  in STL mode.) Either or both cfile and str can be null.
182 
183  This is a formatted print, and will insert
184  tabs and newlines.
185 
186  (For an unformatted stream, use the << operator.)
187  */
188  virtual void Print( FILE* cfile, int depth ) const = 0;
189 
190  /** The world does not agree on whether white space should be kept or
191  not. In order to make everyone happy, these global, static functions
192  are provided to set whether or not TinyXml will condense all white space
193  into a single space or not. The default is to condense. Note changing this
194  value is not thread safe.
195  */
196  static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
197 
198  /// Return the current white space setting.
199  static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
200 
201  /** Return the position, in the original source file, of this node or attribute.
202  The row and column are 1-based. (That is the first row and first column is
203  1,1). If the returns values are 0 or less, then the parser does not have
204  a row and column value.
205 
206  Generally, the row and column value will be set when the TiXmlDocument::Load(),
207  TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set
208  when the DOM was created from operator>>.
209 
210  The values reflect the initial load. Once the DOM is modified programmatically
211  (by adding or changing nodes and attributes) the new values will NOT update to
212  reflect changes in the document.
213 
214  There is a minor performance cost to computing the row and column. Computation
215  can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value.
216 
217  @sa TiXmlDocument::SetTabSize()
218  */
219  int Row() const { return location.row + 1; }
220  int Column() const { return location.col + 1; } ///< See Row()
221 
222  void SetUserData( void* user ) { userData = user; } ///< Set a pointer to arbitrary user data.
223  void* GetUserData() { return userData; } ///< Get a pointer to arbitrary user data.
224  const void* GetUserData() const { return userData; } ///< Get a pointer to arbitrary user data.
225 
226  // Table that returs, for a given lead byte, the total number of bytes
227  // in the UTF-8 sequence.
228  static const int utf8ByteTable[256];
229 
230  virtual const char* Parse( const char* p,
231  TiXmlParsingData* data,
232  TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
233 
234  /** Expands entities in a string. Note this should not contian the tag's '<', '>', etc,
235  or they will be transformed into entities!
236  */
237  static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
238 
239  enum
240  {
257 
259  };
260 
261  protected:
262 
263  static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
264 
265  inline static bool IsWhiteSpace( char c )
266  {
267  return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
268  }
269  inline static bool IsWhiteSpace( int c )
270  {
271  if ( c < 256 )
272  return IsWhiteSpace( (char) c );
273  return false; // Again, only truly correct for English/Latin...but usually works.
274  }
275 
276  static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
277  static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
278 
279  /* Reads an XML name into the string provided. Returns
280  a pointer just past the last character of the name,
281  or 0 if the function has an error.
282  */
283  static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
284 
285  /* Reads text. Returns a pointer past the given end tag.
286  Wickedly complex options, but it keeps the (sensitive) code in one place.
287  */
288  static const char* ReadText( const char* in, // where to start
289  TIXML_STRING* text, // the string read
290  bool ignoreWhiteSpace, // whether to keep the white space
291  const char* endTag, // what ends this text
292  bool ignoreCase, // whether to ignore case in the end tag
293  TiXmlEncoding encoding ); // the current encoding
294 
295  // If an entity has been found, transform it into a character.
296  static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
297 
298  // Get a character, while interpreting entities.
299  // The length can be from 0 to 4 bytes.
300  inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
301  {
302  assert( p );
303  if ( encoding == TIXML_ENCODING_UTF8 )
304  {
305  *length = utf8ByteTable[ *((const unsigned char*)p) ];
306  assert( *length >= 0 && *length < 5 );
307  }
308  else
309  {
310  *length = 1;
311  }
312 
313  if ( *length == 1 )
314  {
315  if ( *p == '&' )
316  return GetEntity( p, _value, length, encoding );
317  *_value = *p;
318  return p+1;
319  }
320  else if ( *length )
321  {
322  //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe),
323  // and the null terminator isn't needed
324  for( int i=0; p[i] && i<*length; ++i ) {
325  _value[i] = p[i];
326  }
327  return p + (*length);
328  }
329  else
330  {
331  // Not valid text.
332  return 0;
333  }
334  }
335 
336  // Return true if the next characters in the stream are any of the endTag sequences.
337  // Ignore case only works for english, and should only be relied on when comparing
338  // to English words: StringEqual( p, "version", true ) is fine.
339  static bool StringEqual( const char* p,
340  const char* endTag,
341  bool ignoreCase,
342  TiXmlEncoding encoding );
343 
344  static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
345 
347 
348  /// Field containing a generic user pointer
349  void* userData;
350 
351  // None of these methods are reliable for any language except English.
352  // Good for approximation, not great for accuracy.
353  static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
354  static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
355  inline static int ToLower( int v, TiXmlEncoding encoding )
356  {
357  if ( encoding == TIXML_ENCODING_UTF8 )
358  {
359  if ( v < 128 ) return tolower( v );
360  return v;
361  }
362  else
363  {
364  return tolower( v );
365  }
366  }
367  static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
368 
369  private:
370  TiXmlBase( const TiXmlBase& ); // not implemented.
371  void operator=( const TiXmlBase& base ); // not allowed.
372 
373  struct Entity
374  {
375  const char* str;
376  unsigned int strLength;
377  char chr;
378  };
379  enum
380  {
383 
384  };
386  static bool condenseWhiteSpace;
387  };
388 
389 
390  /** The parent class for everything in the Document Object Model.
391  (Except for attributes).
392  Nodes have siblings, a parent, and children. A node can be
393  in a document, or stand on its own. The type of a TiXmlNode
394  can be queried, and it can be cast to its more defined type.
395  */
396  class TiXmlNode : public TiXmlBase
397  {
398  friend class TiXmlDocument;
399  friend class TiXmlElement;
400 
401  public:
402 
403  /** An input stream operator, for every class. Tolerant of newlines and
404  formatting, but doesn't expect them.
405  */
406  friend std::istream& operator>> (std::istream& in, TiXmlNode& base);
407 
408  /** An output stream operator, for every class. Note that this outputs
409  without any newlines or formatting, as opposed to Print(), which
410  includes tabs and new lines.
411 
412  The operator<< and operator>> are not completely symmetric. Writing
413  a node to a stream is very well defined. You'll get a nice stream
414  of output, without any extra whitespace or newlines.
415 
416  But reading is not as well defined. (As it always is.) If you create
417  a TiXmlElement (for example) and read that from an input stream,
418  the text needs to define an element or junk will result. This is
419  true of all input streams, but it's worth keeping in mind.
420 
421  A TiXmlDocument will read nodes until it reads a root element, and
422  all the children of that root element.
423  */
424  friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
425 
426  /// Appends the XML node or attribute to a std::string.
427  friend std::string& operator<< (std::string& out, const TiXmlNode& base );
428 
429  /** The types of XML nodes supported by TinyXml. (All the
430  unsupported types are picked up by UNKNOWN.)
431  */
432  enum NodeType
433  {
441  };
442 
443  virtual ~TiXmlNode();
444 
445  /** The meaning of 'value' changes for the specific type of
446  TiXmlNode.
447  @verbatim
448  Document: filename of the xml file
449  Element: name of the element
450  Comment: the comment text
451  Unknown: the tag contents
452  Text: the text string
453  @endverbatim
454 
455  The subclasses will wrap this function.
456  */
457  const char *Value() const { return value.c_str (); }
458 
459  /** Return Value() as a std::string. If you only use STL,
460  this is more efficient than calling Value().
461  Only available in STL mode.
462  */
463  const std::string& ValueStr() const { return value; }
464 
465  const TIXML_STRING& ValueTStr() const { return value; }
466 
467  /** Changes the value of the node. Defined as:
468  @verbatim
469  Document: filename of the xml file
470  Element: name of the element
471  Comment: the comment text
472  Unknown: the tag contents
473  Text: the text string
474  @endverbatim
475  */
476  void SetValue(const char * _value) { value = _value;}
477 
478  /// STL std::string form.
479  void SetValue( const std::string& _value ) { value = _value; }
480 
481  /// Delete all the children of this node. Does not affect 'this'.
482  void Clear();
483 
484  /// One step up the DOM.
485  TiXmlNode* Parent() { return parent; }
486  const TiXmlNode* Parent() const { return parent; }
487 
488  const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children.
490  const TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found.
491  /// The first child of this node with the matching 'value'. Will be null if none found.
492  TiXmlNode* FirstChild( const char * _value ) {
493  // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe)
494  // call the method, cast the return back to non-const.
495  return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
496  }
497  const TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children.
499 
500  const TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children.
501  TiXmlNode* LastChild( const char * _value ) {
502  return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
503  }
504 
505  const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form.
506  TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); } ///< STL std::string form.
507  const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form.
508  TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); } ///< STL std::string form.
509 
510  /** An alternate way to walk the children of a node.
511  One way to iterate over nodes is:
512  @verbatim
513  for( child = parent->FirstChild(); child; child = child->NextSibling() )
514  @endverbatim
515 
516  IterateChildren does the same thing with the syntax:
517  @verbatim
518  child = 0;
519  while( child = parent->IterateChildren( child ) )
520  @endverbatim
521 
522  IterateChildren takes the previous child as input and finds
523  the next one. If the previous child is null, it returns the
524  first. IterateChildren will return null when done.
525  */
526  const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
527  TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
528  return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
529  }
530 
531  /// This flavor of IterateChildren searches for children with a particular 'value'
532  const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
533  TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
534  return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
535  }
536 
537  const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form.
538  TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form.
539 
540  /** Add a new node related to this. Adds a child past the LastChild.
541  Returns a pointer to the new object or NULL if an error occured.
542  */
543  TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
544 
545 
546  /** Add a new node related to this. Adds a child past the LastChild.
547 
548  NOTE: the node to be added is passed by pointer, and will be
549  henceforth owned (and deleted) by tinyXml. This method is efficient
550  and avoids an extra copy, but should be used with care as it
551  uses a different memory model than the other insert functions.
552 
553  @sa InsertEndChild
554  */
555  TiXmlNode* LinkEndChild( TiXmlNode* addThis );
556 
557  /** Add a new node related to this. Adds a child before the specified child.
558  Returns a pointer to the new object or NULL if an error occured.
559  */
560  TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
561 
562  /** Add a new node related to this. Adds a child after the specified child.
563  Returns a pointer to the new object or NULL if an error occured.
564  */
565  TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
566 
567  /** Replace a child of this node.
568  Returns a pointer to the new object or NULL if an error occured.
569  */
570  TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
571 
572  /// Delete a child of this node.
573  bool RemoveChild( TiXmlNode* removeThis );
574 
575  /// Navigate to a sibling node.
576  const TiXmlNode* PreviousSibling() const { return prev; }
578 
579  /// Navigate to a sibling node.
580  const TiXmlNode* PreviousSibling( const char * ) const;
581  TiXmlNode* PreviousSibling( const char *_prev ) {
582  return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
583  }
584 
585  const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form.
586  TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); } ///< STL std::string form.
587  const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form.
588  TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); } ///< STL std::string form.
589 
590  /// Navigate to a sibling node.
591  const TiXmlNode* NextSibling() const { return next; }
592  TiXmlNode* NextSibling() { return next; }
593 
594  /// Navigate to a sibling node with the given 'value'.
595  const TiXmlNode* NextSibling( const char * ) const;
596  TiXmlNode* NextSibling( const char* _next ) {
597  return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
598  }
599 
600  /** Convenience function to get through elements.
601  Calls NextSibling and ToElement. Will skip all non-Element
602  nodes. Returns 0 if there is not another element.
603  */
604  const TiXmlElement* NextSiblingElement() const;
606  return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
607  }
608 
609  /** Convenience function to get through elements.
610  Calls NextSibling and ToElement. Will skip all non-Element
611  nodes. Returns 0 if there is not another element.
612  */
613  const TiXmlElement* NextSiblingElement( const char * ) const;
614  TiXmlElement* NextSiblingElement( const char *_next ) {
615  return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
616  }
617 
618  const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form.
619  TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form.
620 
621  /// Convenience function to get through elements.
622  const TiXmlElement* FirstChildElement() const;
624  return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
625  }
626 
627  /// Convenience function to get through elements.
628  const TiXmlElement* FirstChildElement( const char * _value ) const;
629  TiXmlElement* FirstChildElement( const char * _value ) {
630  return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
631  }
632 
633  const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form.
634  TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); } ///< STL std::string form.
635 
636  /** Query the type (as an enumerated value, above) of this node.
637  The possible types are: TINYXML_DOCUMENT, TINYXML_ELEMENT, TINYXML_COMMENT,
638  TINYXML_UNKNOWN, TINYXML_TEXT, and TINYXML_DECLARATION.
639  */
640  int Type() const { return type; }
641 
642  /** Return a pointer to the Document this node lives in.
643  Returns null if not in a document.
644  */
645  const TiXmlDocument* GetDocument() const;
647  return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
648  }
649 
650  /// Returns true if this node has no children.
651  bool NoChildren() const { return !firstChild; }
652 
653  virtual const TiXmlDocument* ToDocument() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
654  virtual const TiXmlElement* ToElement() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
655  virtual const TiXmlComment* ToComment() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
656  virtual const TiXmlUnknown* ToUnknown() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
657  virtual const TiXmlText* ToText() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
658  virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
659 
660  virtual TiXmlDocument* ToDocument() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
661  virtual TiXmlElement* ToElement() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
662  virtual TiXmlComment* ToComment() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
663  virtual TiXmlUnknown* ToUnknown() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
664  virtual TiXmlText* ToText() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
665  virtual TiXmlDeclaration* ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
666 
667  /** Create an exact duplicate of this node and return it. The memory must be deleted
668  by the caller.
669  */
670  virtual TiXmlNode* Clone() const = 0;
671 
672  /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the
673  XML tree will be conditionally visited and the host will be called back
674  via the TiXmlVisitor interface.
675 
676  This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse
677  the XML for the callbacks, so the performance of TinyXML is unchanged by using this
678  interface versus any other.)
679 
680  The interface has been based on ideas from:
681 
682  - http://www.saxproject.org/
683  - http://c2.com/cgi/wiki?HierarchicalVisitorPattern
684 
685  Which are both good references for "visiting".
686 
687  An example of using Accept():
688  @verbatim
689  TiXmlPrinter printer;
690  tinyxmlDoc.Accept( &printer );
691  const char* xmlcstr = printer.CStr();
692  @endverbatim
693  */
694  virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
695 
696  // The real work of the input operator.
697  virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
698 
699  protected:
700  TiXmlNode( NodeType _type );
701 
702  // Copy to the allocated object. Shared functionality between Clone, Copy constructor,
703  // and the assignment operator.
704  void CopyTo( TiXmlNode* target ) const;
705 
706  // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
707  TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
708 
711 
714 
716 
719 
720  private:
721  TiXmlNode( const TiXmlNode& ); // not implemented.
722  void operator=( const TiXmlNode& base ); // not allowed.
723  };
724 
725 
726  /** An attribute is a name-value pair. Elements have an arbitrary
727  number of attributes, each with a unique name.
728 
729  @note The attributes are not TiXmlNodes, since they are not
730  part of the tinyXML document object model. There are other
731  suggested ways to look at this problem.
732  */
733  class TiXmlAttribute : public TiXmlBase
734  {
735  friend class TiXmlAttributeSet;
736 
737  public:
738  /// Construct an empty attribute.
740  {
741  document = 0;
742  prev = next = 0;
743  }
744 
745  /// std::string constructor.
746  TiXmlAttribute( const std::string& _name, const std::string& _value )
747  {
748  name = _name;
749  value = _value;
750  document = 0;
751  prev = next = 0;
752  }
753 
754  /// Construct an attribute with a name and value.
755  TiXmlAttribute( const char * _name, const char * _value )
756  {
757  name = _name;
758  value = _value;
759  document = 0;
760  prev = next = 0;
761  }
762 
763  const char* Name() const { return name.c_str(); } ///< Return the name of this attribute.
764  const char* Value() const { return value.c_str(); } ///< Return the value of this attribute.
765  const std::string& ValueStr() const { return value; } ///< Return the value of this attribute.
766  int IntValue() const; ///< Return the value of this attribute, converted to an integer.
767  double DoubleValue() const; ///< Return the value of this attribute, converted to a double.
768 
769  // Get the tinyxml string representation
770  const TIXML_STRING& NameTStr() const { return name; }
771 
772  /** QueryIntValue examines the value string. It is an alternative to the
773  IntValue() method with richer error checking.
774  If the value is an integer, it is stored in 'value' and
775  the call returns TIXML_SUCCESS. If it is not
776  an integer, it returns TIXML_WRONG_TYPE.
777 
778  A specialized but useful call. Note that for success it returns 0,
779  which is the opposite of almost all other TinyXml calls.
780  */
781  int QueryIntValue( int* _value ) const;
782  /// QueryDoubleValue examines the value string. See QueryIntValue().
783  int QueryDoubleValue( double* _value ) const;
784 
785  void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute.
786  void SetValue( const char* _value ) { value = _value; } ///< Set the value.
787 
788  void SetIntValue( int _value ); ///< Set the value from an integer.
789  void SetDoubleValue( double _value ); ///< Set the value from a double.
790 
791  /// STL std::string form.
792  void SetName( const std::string& _name ) { name = _name; }
793  /// STL std::string form.
794  void SetValue( const std::string& _value ) { value = _value; }
795 
796  /// Get the next sibling attribute in the DOM. Returns null at end.
797  const TiXmlAttribute* Next() const;
799  return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
800  }
801 
802  /// Get the previous sibling attribute in the DOM. Returns null at beginning.
803  const TiXmlAttribute* Previous() const;
805  return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
806  }
807 
808  bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
809  bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
810  bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
811 
812  /* Attribute parsing starts: first letter of the name
813  returns: the next char after the value end quote
814  */
815  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
816 
817  // Prints this Attribute to a FILE stream.
818  virtual void Print( FILE* cfile, int depth ) const {
819  Print( cfile, depth, 0 );
820  }
821  void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
822 
823  // [internal use]
824  // Set the document pointer so the attribute can report errors.
825  void SetDocument( TiXmlDocument* doc ) { document = doc; }
826 
827  private:
828  TiXmlAttribute( const TiXmlAttribute& ); // not implemented.
829  void operator=( const TiXmlAttribute& base ); // not allowed.
830 
831  TiXmlDocument* document; // A pointer back to a document, for error reporting.
836  };
837 
838 
839  /* A class used to manage a group of attributes.
840  It is only used internally, both by the ELEMENT and the DECLARATION.
841 
842  The set can be changed transparent to the Element and Declaration
843  classes that use it, but NOT transparent to the Attribute
844  which has to implement a next() and previous() method. Which makes
845  it a bit problematic and prevents the use of STL.
846 
847  This version is implemented with circular lists because:
848  - I like circular lists
849  - it demonstrates some independence from the (typical) doubly linked list.
850  */
852  {
853  public:
856 
857  void Add( TiXmlAttribute* attribute );
858  void Remove( TiXmlAttribute* attribute );
859 
860  const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
861  TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
862  const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
863  TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
864 
865  TiXmlAttribute* Find( const char* _name ) const;
866  TiXmlAttribute* FindOrCreate( const char* _name );
867 
868  TiXmlAttribute* Find( const std::string& _name ) const;
869  TiXmlAttribute* FindOrCreate( const std::string& _name );
870 
871  private:
872  //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
873  //*ME: this class must be also use a hidden/disabled copy-constructor !!!
874  TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed
875  void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute)
876 
878  };
879 
880 
881  /** The element is a container class. It has a value, the element name,
882  and can contain other elements, text, comments, and unknowns.
883  Elements also contain an arbitrary number of attributes.
884  */
885  class TiXmlElement : public TiXmlNode
886  {
887  public:
888  /// Construct an element.
889  TiXmlElement (const char * in_value);
890 
891  /// std::string constructor.
892  TiXmlElement( const std::string& _value );
893 
894  TiXmlElement( const TiXmlElement& );
895 
896  TiXmlElement& operator=( const TiXmlElement& base );
897 
898  virtual ~TiXmlElement();
899 
900  /** Given an attribute name, Attribute() returns the value
901  for the attribute of that name, or null if none exists.
902  */
903  const char* Attribute( const char* name ) const;
904 
905  /** Given an attribute name, Attribute() returns the value
906  for the attribute of that name, or null if none exists.
907  If the attribute exists and can be converted to an integer,
908  the integer value will be put in the return 'i', if 'i'
909  is non-null.
910  */
911  const char* Attribute( const char* name, int* i ) const;
912 
913  /** Given an attribute name, Attribute() returns the value
914  for the attribute of that name, or null if none exists.
915  If the attribute exists and can be converted to an double,
916  the double value will be put in the return 'd', if 'd'
917  is non-null.
918  */
919  const char* Attribute( const char* name, double* d ) const;
920 
921  /** QueryIntAttribute examines the attribute - it is an alternative to the
922  Attribute() method with richer error checking.
923  If the attribute is an integer, it is stored in 'value' and
924  the call returns TIXML_SUCCESS. If it is not
925  an integer, it returns TIXML_WRONG_TYPE. If the attribute
926  does not exist, then TIXML_NO_ATTRIBUTE is returned.
927  */
928  int QueryIntAttribute( const char* name, int* _value ) const;
929  /// QueryUnsignedAttribute examines the attribute - see QueryIntAttribute().
930  int QueryUnsignedAttribute( const char* name, unsigned* _value ) const;
931  /** QueryBoolAttribute examines the attribute - see QueryIntAttribute().
932  Note that '1', 'true', or 'yes' are considered true, while '0', 'false'
933  and 'no' are considered false.
934  */
935  int QueryBoolAttribute( const char* name, bool* _value ) const;
936  /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
937  int QueryDoubleAttribute( const char* name, double* _value ) const;
938  /// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
939  int QueryFloatAttribute( const char* name, float* _value ) const {
940  double d;
941  int result = QueryDoubleAttribute( name, &d );
942  if ( result == TIXML_SUCCESS ) {
943  *_value = (float)d;
944  }
945  return result;
946  }
947 
948  /// QueryStringAttribute examines the attribute - see QueryIntAttribute().
949  int QueryStringAttribute( const char* name, std::string* _value ) const {
950  const char* cstr = Attribute( name );
951  if ( cstr ) {
952  *_value = std::string( cstr );
953  return TIXML_SUCCESS;
954  }
955  return TIXML_NO_ATTRIBUTE;
956  }
957 
958  /** Template form of the attribute query which will try to read the
959  attribute into the specified type. Very easy, very powerful, but
960  be careful to make sure to call this with the correct type.
961 
962  NOTE: This method doesn't work correctly for 'string' types that contain spaces.
963 
964  @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE
965  */
966  template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
967  {
968  const TiXmlAttribute* node = attributeSet.Find( name );
969  if ( !node )
970  return TIXML_NO_ATTRIBUTE;
971 
972  std::stringstream sstream( node->ValueStr() );
973  sstream >> *outValue;
974  if ( !sstream.fail() )
975  return TIXML_SUCCESS;
976  return TIXML_WRONG_TYPE;
977  }
978 
979  int QueryValueAttribute( const std::string& name, std::string* outValue ) const
980  {
981  const TiXmlAttribute* node = attributeSet.Find( name );
982  if ( !node )
983  return TIXML_NO_ATTRIBUTE;
984  *outValue = node->ValueStr();
985  return TIXML_SUCCESS;
986  }
987 
988  /** Sets an attribute of name to a given value. The attribute
989  will be created if it does not exist, or changed if it does.
990  */
991  void SetAttribute( const char* name, const char * _value );
992 
993  const std::string* Attribute( const std::string& name ) const;
994  const std::string* Attribute( const std::string& name, int* i ) const;
995  const std::string* Attribute( const std::string& name, double* d ) const;
996  int QueryIntAttribute( const std::string& name, int* _value ) const;
997  int QueryDoubleAttribute( const std::string& name, double* _value ) const;
998 
999  /// STL std::string form.
1000  void SetAttribute( const std::string& name, const std::string& _value );
1001  ///< STL std::string form.
1002  void SetAttribute( const std::string& name, int _value );
1003  ///< STL std::string form.
1004  void SetDoubleAttribute( const std::string& name, double value );
1005 
1006  /** Sets an attribute of name to a given value. The attribute
1007  will be created if it does not exist, or changed if it does.
1008  */
1009  void SetAttribute( const char * name, int value );
1010 
1011  /** Sets an attribute of name to a given value. The attribute
1012  will be created if it does not exist, or changed if it does.
1013  */
1014  void SetDoubleAttribute( const char * name, double value );
1015 
1016  /** Deletes an attribute with the given name.
1017  */
1018  void RemoveAttribute( const char * name );
1019  void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form.
1020 
1021  const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element.
1023  const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element.
1025 
1026  /** Convenience function for easy access to the text inside an element. Although easy
1027  and concise, GetText() is limited compared to getting the TiXmlText child
1028  and accessing it directly.
1029 
1030  If the first child of 'this' is a TiXmlText, the GetText()
1031  returns the character string of the Text node, else null is returned.
1032 
1033  This is a convenient method for getting the text of simple contained text:
1034  @verbatim
1035  <foo>This is text</foo>
1036  const char* str = fooElement->GetText();
1037  @endverbatim
1038 
1039  'str' will be a pointer to "This is text".
1040 
1041  Note that this function can be misleading. If the element foo was created from
1042  this XML:
1043  @verbatim
1044  <foo><b>This is text</b></foo>
1045  @endverbatim
1046 
1047  then the value of str would be null. The first child node isn't a text node, it is
1048  another element. From this XML:
1049  @verbatim
1050  <foo>This is <b>text</b></foo>
1051  @endverbatim
1052  GetText() will return "This is ".
1053 
1054  WARNING: GetText() accesses a child node - don't become confused with the
1055  similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are
1056  safe type casts on the referenced node.
1057  */
1058  const char* GetText() const;
1059 
1060  /// Creates a new Element and returns it - the returned element is a copy.
1061  virtual TiXmlNode* Clone() const;
1062  // Print the Element to a FILE stream.
1063  virtual void Print( FILE* cfile, int depth ) const;
1064 
1065  /* Attribtue parsing starts: next char past '<'
1066  returns: next char past '>'
1067  */
1068  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1069 
1070  virtual const TiXmlElement* ToElement() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1071  virtual TiXmlElement* ToElement() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1072 
1073  /** Walk the XML tree visiting this node and all of its children.
1074  */
1075  virtual bool Accept( TiXmlVisitor* visitor ) const;
1076 
1077  protected:
1078 
1079  void CopyTo( TiXmlElement* target ) const;
1080  void ClearThis(); // like clear, but initializes 'this' object as well
1081 
1082  // Used to be public [internal use]
1083  virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1084 
1085  /* [internal use]
1086  Reads the "value" of the element -- another element, or text.
1087  This should terminate with the current end tag.
1088  */
1089  const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1090 
1091  private:
1093  };
1094 
1095 
1096  /** An XML comment.
1097  */
1098  class TiXmlComment : public TiXmlNode
1099  {
1100  public:
1101  /// Constructs an empty comment.
1103  /// Construct a comment from text.
1104  TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {
1105  SetValue( _value );
1106  }
1107  TiXmlComment( const TiXmlComment& );
1108  TiXmlComment& operator=( const TiXmlComment& base );
1109 
1110  virtual ~TiXmlComment() {}
1111 
1112  /// Returns a copy of this Comment.
1113  virtual TiXmlNode* Clone() const;
1114  // Write this Comment to a FILE stream.
1115  virtual void Print( FILE* cfile, int depth ) const;
1116 
1117  /* Attribtue parsing starts: at the ! of the !--
1118  returns: next char past '>'
1119  */
1120  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1121 
1122  virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1123  virtual TiXmlComment* ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1124 
1125  /** Walk the XML tree visiting this node and all of its children.
1126  */
1127  virtual bool Accept( TiXmlVisitor* visitor ) const;
1128 
1129  protected:
1130  void CopyTo( TiXmlComment* target ) const;
1131 
1132  // used to be public
1133  virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1134  // virtual void StreamOut( TIXML_OSTREAM * out ) const;
1135 
1136  private:
1137 
1138  };
1139 
1140 
1141  /** XML text. A text node can have 2 ways to output the next. "normal" output
1142  and CDATA. It will default to the mode it was parsed from the XML file and
1143  you generally want to leave it alone, but you can change the output mode with
1144  SetCDATA() and query it with CDATA().
1145  */
1146  class TiXmlText : public TiXmlNode
1147  {
1148  friend class TiXmlElement;
1149  public:
1150  /** Constructor for text element. By default, it is treated as
1151  normal, encoded text. If you want it be output as a CDATA text
1152  element, set the parameter _cdata to 'true'
1153  */
1154  TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
1155  {
1156  SetValue( initValue );
1157  cdata = false;
1158  }
1159  virtual ~TiXmlText() {}
1160 
1161  /// Constructor.
1162  TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
1163  {
1164  SetValue( initValue );
1165  cdata = false;
1166  }
1167 
1168  TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); }
1169  TiXmlText& operator=( const TiXmlText& base ) { base.CopyTo( this ); return *this; }
1170 
1171  // Write this text object to a FILE stream.
1172  virtual void Print( FILE* cfile, int depth ) const;
1173 
1174  /// Queries whether this represents text using a CDATA section.
1175  bool CDATA() const { return cdata; }
1176  /// Turns on or off a CDATA representation of text.
1177  void SetCDATA( bool _cdata ) { cdata = _cdata; }
1178 
1179  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1180 
1181  virtual const TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1182  virtual TiXmlText* ToText() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1183 
1184  /** Walk the XML tree visiting this node and all of its children.
1185  */
1186  virtual bool Accept( TiXmlVisitor* content ) const;
1187 
1188  protected :
1189  /// [internal use] Creates a new Element and returns it.
1190  virtual TiXmlNode* Clone() const;
1191  void CopyTo( TiXmlText* target ) const;
1192 
1193  bool Blank() const; // returns true if all white space and new lines
1194  // [internal use]
1195  virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1196 
1197  private:
1198  bool cdata; // true if this should be input and output as a CDATA style text element
1199  };
1200 
1201 
1202  /** In correct XML the declaration is the first entry in the file.
1203  @verbatim
1204  <?xml version="1.0" standalone="yes"?>
1205  @endverbatim
1206 
1207  TinyXml will happily read or write files without a declaration,
1208  however. There are 3 possible attributes to the declaration:
1209  version, encoding, and standalone.
1210 
1211  Note: In this version of the code, the attributes are
1212  handled as special cases, not generic attributes, simply
1213  because there can only be at most 3 and they are always the same.
1214  */
1216  {
1217  public:
1218  /// Construct an empty declaration.
1220 
1221  /// Constructor.
1222  TiXmlDeclaration( const std::string& _version,
1223  const std::string& _encoding,
1224  const std::string& _standalone );
1225 
1226  /// Construct.
1227  TiXmlDeclaration( const char* _version,
1228  const char* _encoding,
1229  const char* _standalone );
1230 
1231  TiXmlDeclaration( const TiXmlDeclaration& copy );
1233 
1234  virtual ~TiXmlDeclaration() {}
1235 
1236  /// Version. Will return an empty string if none was found.
1237  const char *Version() const { return version.c_str (); }
1238  /// Encoding. Will return an empty string if none was found.
1239  const char *Encoding() const { return encoding.c_str (); }
1240  /// Is this a standalone document?
1241  const char *Standalone() const { return standalone.c_str (); }
1242 
1243  /// Creates a copy of this Declaration and returns it.
1244  virtual TiXmlNode* Clone() const;
1245  // Print this declaration to a FILE stream.
1246  virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
1247  virtual void Print( FILE* cfile, int depth ) const {
1248  Print( cfile, depth, 0 );
1249  }
1250 
1251  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1252 
1253  virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1254  virtual TiXmlDeclaration* ToDeclaration() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1255 
1256  /** Walk the XML tree visiting this node and all of its children.
1257  */
1258  virtual bool Accept( TiXmlVisitor* visitor ) const;
1259 
1260  protected:
1261  void CopyTo( TiXmlDeclaration* target ) const;
1262  // used to be public
1263  virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1264 
1265  private:
1266 
1270  };
1271 
1272 
1273  /** Any tag that tinyXml doesn't recognize is saved as an
1274  unknown. It is a tag of text, but should not be modified.
1275  It will be written back to the XML, unchanged, when the file
1276  is saved.
1277 
1278  DTD tags get thrown into TiXmlUnknowns.
1279  */
1280  class TiXmlUnknown : public TiXmlNode
1281  {
1282  public:
1284  virtual ~TiXmlUnknown() {}
1285 
1286  TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) { copy.CopyTo( this ); }
1287  TiXmlUnknown& operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); return *this; }
1288 
1289  /// Creates a copy of this Unknown and returns it.
1290  virtual TiXmlNode* Clone() const;
1291  // Print this Unknown to a FILE stream.
1292  virtual void Print( FILE* cfile, int depth ) const;
1293 
1294  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1295 
1296  virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1297  virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1298 
1299  /** Walk the XML tree visiting this node and all of its children.
1300  */
1301  virtual bool Accept( TiXmlVisitor* content ) const;
1302 
1303  protected:
1304  void CopyTo( TiXmlUnknown* target ) const;
1305  virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1306 
1307  private:
1308 
1309  };
1310 
1311 
1312  /** Always the top level node. A document binds together all the
1313  XML pieces. It can be saved, loaded, and printed to the screen.
1314  The 'value' of a document node is the xml file name.
1315  */
1316  class TiXmlDocument : public TiXmlNode
1317  {
1318  public:
1319  /// Create an empty document, that has no name.
1320  TiXmlDocument();
1321  /// Create a document with a name. The name of the document is also the filename of the xml.
1322  TiXmlDocument( const char * documentName );
1323 
1324  /// Constructor.
1325  TiXmlDocument( const std::string& documentName );
1326 
1327  TiXmlDocument( const TiXmlDocument& copy );
1328  TiXmlDocument& operator=( const TiXmlDocument& copy );
1329 
1330  virtual ~TiXmlDocument() {}
1331 
1332  /** Load a file using the current document value.
1333  Returns true if successful. Will delete any existing
1334  document data before loading.
1335  */
1336  bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1337  /// Save a file using the current document value. Returns true if successful.
1338  bool SaveFile() const;
1339  /// Load a file using the given filename. Returns true if successful.
1340  bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1341  /// Save a file using the given filename. Returns true if successful.
1342  bool SaveFile( const char * filename ) const;
1343  /** Load a file using the given FILE*. Returns true if successful. Note that this method
1344  doesn't stream - the entire object pointed at by the FILE*
1345  will be interpreted as an XML file. TinyXML doesn't stream in XML from the current
1346  file location. Streaming may be added in the future.
1347  */
1348  bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1349  /// Save a file using the given FILE*. Returns true if successful.
1350  bool SaveFile( FILE* ) const;
1351 
1352  bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version.
1353  {
1354  return LoadFile( filename.c_str(), encoding );
1355  }
1356  bool SaveFile( const std::string& filename ) const ///< STL std::string version.
1357  {
1358  return SaveFile( filename.c_str() );
1359  }
1360 
1361  /** Parse the given null terminated block of xml data. Passing in an encoding to this
1362  method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml
1363  to use that encoding, regardless of what TinyXml might otherwise try to detect.
1364  */
1365  virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1366 
1367  /** Get the root element -- the only top level element -- of the document.
1368  In well formed XML, there should only be one. TinyXml is tolerant of
1369  multiple elements at the document level.
1370  */
1371  const TiXmlElement* RootElement() const { return FirstChildElement(); }
1373 
1374  /** If an error occurs, Error will be set to true. Also,
1375  - The ErrorId() will contain the integer identifier of the error (not generally useful)
1376  - The ErrorDesc() method will return the name of the error. (very useful)
1377  - The ErrorRow() and ErrorCol() will return the location of the error (if known)
1378  */
1379  bool Error() const { return error; }
1380 
1381  /// Contains a textual (english) description of the error if one occurs.
1382  const char * ErrorDesc() const { return errorDesc.c_str (); }
1383 
1384  /** Generally, you probably want the error string ( ErrorDesc() ). But if you
1385  prefer the ErrorId, this function will fetch it.
1386  */
1387  int ErrorId() const { return errorId; }
1388 
1389  /** Returns the location (if known) of the error. The first column is column 1,
1390  and the first row is row 1. A value of 0 means the row and column wasn't applicable
1391  (memory errors, for example, have no row/column) or the parser lost the error. (An
1392  error in the error reporting, in that case.)
1393 
1394  @sa SetTabSize, Row, Column
1395  */
1396  int ErrorRow() const { return errorLocation.row+1; }
1397  int ErrorCol() const { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow()
1398 
1399  /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())
1400  to report the correct values for row and column. It does not change the output
1401  or input in any way.
1402 
1403  By calling this method, with a tab size
1404  greater than 0, the row and column of each node and attribute is stored
1405  when the file is loaded. Very useful for tracking the DOM back in to
1406  the source file.
1407 
1408  The tab size is required for calculating the location of nodes. If not
1409  set, the default of 4 is used. The tabsize is set per document. Setting
1410  the tabsize to 0 disables row/column tracking.
1411 
1412  Note that row and column tracking is not supported when using operator>>.
1413 
1414  The tab size needs to be enabled before the parse or load. Correct usage:
1415  @verbatim
1416  TiXmlDocument doc;
1417  doc.SetTabSize( 8 );
1418  doc.Load( "myfile.xml" );
1419  @endverbatim
1420 
1421  @sa Row, Column
1422  */
1423  void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
1424 
1425  int TabSize() const { return tabsize; }
1426 
1427  /** If you have handled the error, it can be reset with this call. The error
1428  state is automatically cleared if you Parse a new XML block.
1429  */
1430  void ClearError() { error = false;
1431  errorId = 0;
1432  errorDesc = "";
1434  //errorLocation.last = 0;
1435  }
1436 
1437  /** Write the document to standard out using formatted printing ("pretty print"). */
1438  void Print() const { Print( stdout, 0 ); }
1439 
1440  /* Write the document to a string using formatted printing ("pretty print"). This
1441  will allocate a character array (new char[]) and return it as a pointer. The
1442  calling code pust call delete[] on the return char* to avoid a memory leak.
1443  */
1444  //char* PrintToMemory() const;
1445 
1446  /// Print this Document to a FILE stream.
1447  virtual void Print( FILE* cfile, int depth = 0 ) const;
1448  // [internal use]
1449  void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1450 
1451  virtual const TiXmlDocument* ToDocument() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1452  virtual TiXmlDocument* ToDocument() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1453 
1454  /** Walk the XML tree visiting this node and all of its children.
1455  */
1456  virtual bool Accept( TiXmlVisitor* content ) const;
1457 
1458  protected :
1459  // [internal use]
1460  virtual TiXmlNode* Clone() const;
1461  virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1462 
1463  private:
1464  void CopyTo( TiXmlDocument* target ) const;
1465 
1466  bool error;
1467  int errorId;
1469  int tabsize;
1471  bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write.
1472  };
1473 
1474 
1475  /**
1476  A TiXmlHandle is a class that wraps a node pointer with null checks; this is
1477  an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml
1478  DOM structure. It is a separate utility class.
1479 
1480  Take an example:
1481  @verbatim
1482  <Document>
1483  <Element attributeA = "valueA">
1484  <Child attributeB = "value1" />
1485  <Child attributeB = "value2" />
1486  </Element>
1487  <Document>
1488  @endverbatim
1489 
1490  Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very
1491  easy to write a *lot* of code that looks like:
1492 
1493  @verbatim
1494  TiXmlElement* root = document.FirstChildElement( "Document" );
1495  if ( root )
1496  {
1497  TiXmlElement* element = root->FirstChildElement( "Element" );
1498  if ( element )
1499  {
1500  TiXmlElement* child = element->FirstChildElement( "Child" );
1501  if ( child )
1502  {
1503  TiXmlElement* child2 = child->NextSiblingElement( "Child" );
1504  if ( child2 )
1505  {
1506  // Finally do something useful.
1507  @endverbatim
1508 
1509  And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity
1510  of such code. A TiXmlHandle checks for null pointers so it is perfectly safe
1511  and correct to use:
1512 
1513  @verbatim
1514  TiXmlHandle docHandle( &document );
1515  TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement();
1516  if ( child2 )
1517  {
1518  // do something useful
1519  @endverbatim
1520 
1521  Which is MUCH more concise and useful.
1522 
1523  It is also safe to copy handles - internally they are nothing more than node pointers.
1524  @verbatim
1525  TiXmlHandle handleCopy = handle;
1526  @endverbatim
1527 
1528  What they should not be used for is iteration:
1529 
1530  @verbatim
1531  int i=0;
1532  while ( true )
1533  {
1534  TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement();
1535  if ( !child )
1536  break;
1537  // do something
1538  ++i;
1539  }
1540  @endverbatim
1541 
1542  It seems reasonable, but it is in fact two embedded while loops. The Child method is
1543  a linear walk to find the element, so this code would iterate much more than it needs
1544  to. Instead, prefer:
1545 
1546  @verbatim
1547  TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement();
1548 
1549  for( child; child; child=child->NextSiblingElement() )
1550  {
1551  // do something
1552  }
1553  @endverbatim
1554  */
1556  {
1557  public:
1558  /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
1559  TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
1560  /// Copy constructor
1561  TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
1562  TiXmlHandle operator=( const TiXmlHandle& ref ) { if ( &ref != this ) this->node = ref.node; return *this; }
1563 
1564  /// Return a handle to the first child node.
1565  TiXmlHandle FirstChild() const;
1566  /// Return a handle to the first child node with the given name.
1567  TiXmlHandle FirstChild( const char * value ) const;
1568  /// Return a handle to the first child element.
1570  /// Return a handle to the first child element with the given name.
1571  TiXmlHandle FirstChildElement( const char * value ) const;
1572 
1573  /** Return a handle to the "index" child with the given name.
1574  The first child is 0, the second 1, etc.
1575  */
1576  TiXmlHandle Child( const char* value, int index ) const;
1577  /** Return a handle to the "index" child.
1578  The first child is 0, the second 1, etc.
1579  */
1580  TiXmlHandle Child( int index ) const;
1581  /** Return a handle to the "index" child element with the given name.
1582  The first child element is 0, the second 1, etc. Note that only TiXmlElements
1583  are indexed: other types are not counted.
1584  */
1585  TiXmlHandle ChildElement( const char* value, int index ) const;
1586  /** Return a handle to the "index" child element.
1587  The first child element is 0, the second 1, etc. Note that only TiXmlElements
1588  are indexed: other types are not counted.
1589  */
1590  TiXmlHandle ChildElement( int index ) const;
1591 
1592  TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
1593  TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
1594 
1595  TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
1596  TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
1597 
1598  /** Return the handle as a TiXmlNode. This may return null.
1599  */
1600  TiXmlNode* ToNode() const { return node; }
1601  /** Return the handle as a TiXmlElement. This may return null.
1602  */
1603  TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
1604  /** Return the handle as a TiXmlText. This may return null.
1605  */
1606  TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
1607  /** Return the handle as a TiXmlUnknown. This may return null.
1608  */
1609  TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
1610 
1611  /** @deprecated use ToNode.
1612  Return the handle as a TiXmlNode. This may return null.
1613  */
1614  TiXmlNode* Node() const { return ToNode(); }
1615  /** @deprecated use ToElement.
1616  Return the handle as a TiXmlElement. This may return null.
1617  */
1618  TiXmlElement* Element() const { return ToElement(); }
1619  /** @deprecated use ToText()
1620  Return the handle as a TiXmlText. This may return null.
1621  */
1622  TiXmlText* Text() const { return ToText(); }
1623  /** @deprecated use ToUnknown()
1624  Return the handle as a TiXmlUnknown. This may return null.
1625  */
1626  TiXmlUnknown* Unknown() const { return ToUnknown(); }
1627 
1628  private:
1630  };
1631 
1632 
1633  /** Print to memory functionality. The TiXmlPrinter is useful when you need to:
1634 
1635  -# Print to memory (especially in non-STL mode)
1636  -# Control formatting (line endings, etc.)
1637 
1638  When constructed, the TiXmlPrinter is in its default "pretty printing" mode.
1639  Before calling Accept() you can call methods to control the printing
1640  of the XML document. After TiXmlNode::Accept() is called, the printed document can
1641  be accessed via the CStr(), Str(), and Size() methods.
1642 
1643  TiXmlPrinter uses the Visitor API.
1644  @verbatim
1645  TiXmlPrinter printer;
1646  printer.SetIndent( "\t" );
1647 
1648  doc.Accept( &printer );
1649  fprintf( stdout, "%s", printer.CStr() );
1650  @endverbatim
1651  */
1653  {
1654  public:
1655  TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
1656  buffer(), indent( " " ), lineBreak( "\n" ) {}
1657 
1658  virtual bool VisitEnter( const TiXmlDocument& doc );
1659  virtual bool VisitExit( const TiXmlDocument& doc );
1660 
1661  virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
1662  virtual bool VisitExit( const TiXmlElement& element );
1663 
1664  virtual bool Visit( const TiXmlDeclaration& declaration );
1665  virtual bool Visit( const TiXmlText& text );
1666  virtual bool Visit( const TiXmlComment& comment );
1667  virtual bool Visit( const TiXmlUnknown& unknown );
1668 
1669  /** Set the indent characters for printing. By default 4 spaces
1670  but tab (\t) is also useful, or null/empty string for no indentation.
1671  */
1672  void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
1673  /// Query the indention string.
1674  const char* Indent() { return indent.c_str(); }
1675  /** Set the line breaking string. By default set to newline (\n).
1676  Some operating systems prefer other characters, or can be
1677  set to the null/empty string for no indenation.
1678  */
1679  void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
1680  /// Query the current line breaking string.
1681  const char* LineBreak() { return lineBreak.c_str(); }
1682 
1683  /** Switch over to "stream printing" which is the most dense formatting without
1684  linebreaks. Common when the XML is needed for network transmission.
1685  */
1686  void SetStreamPrinting() { indent = "";
1687  lineBreak = "";
1688  }
1689  /// Return the result.
1690  const char* CStr() { return buffer.c_str(); }
1691  /// Return the length of the result string.
1692  size_t Size() { return buffer.size(); }
1693 
1694  /// Return the result.
1695  const std::string& Str() { return buffer; }
1696 
1697  private:
1698  void DoIndent() {
1699  for( int i=0; i<depth; ++i )
1700  buffer += indent;
1701  }
1702  void DoLineBreak() {
1703  buffer += lineBreak;
1704  }
1705 
1706  int depth;
1711  };
1712 
1713 };
void Remove(TiXmlAttribute *attribute)
Definition: tinyxml.cpp:1491
TiXmlAttribute * Find(const char *_name) const
Definition: tinyxml.cpp:1532
TiXmlAttribute * Last()
Definition: tinyxml.h:863
TiXmlAttributeSet(const TiXmlAttributeSet &)
void Add(TiXmlAttribute *attribute)
Definition: tinyxml.cpp:1480
void operator=(const TiXmlAttributeSet &)
const TiXmlAttribute * First() const
Definition: tinyxml.h:860
TiXmlAttribute * First()
Definition: tinyxml.h:861
const TiXmlAttribute * Last() const
Definition: tinyxml.h:862
TiXmlAttribute * FindOrCreate(const char *_name)
Definition: tinyxml.cpp:1543
TiXmlAttribute sentinel
Definition: tinyxml.h:877
An attribute is a name-value pair.
Definition: tinyxml.h:734
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
void SetIntValue(int _value)
Set the value from an integer.
Definition: tinyxml.cpp:1218
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
Definition: tinyxml.cpp:1158
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition: tinyxml.h:818
void SetName(const std::string &_name)
STL std::string form.
Definition: tinyxml.h:792
double DoubleValue() const
Return the value of this attribute, converted to a double.
Definition: tinyxml.cpp:1245
int IntValue() const
Return the value of this attribute, converted to an integer.
Definition: tinyxml.cpp:1240
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:764
TIXML_STRING value
Definition: tinyxml.h:833
void SetDocument(TiXmlDocument *doc)
Definition: tinyxml.h:825
void SetDoubleValue(double _value)
Set the value from a double.
Definition: tinyxml.cpp:1229
const TIXML_STRING & NameTStr() const
Definition: tinyxml.h:770
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Definition: tinyxml.cpp:1138
bool operator==(const TiXmlAttribute &rhs) const
Definition: tinyxml.h:808
TiXmlDocument * document
Definition: tinyxml.h:831
TiXmlAttribute(const std::string &_name, const std::string &_value)
std::string constructor.
Definition: tinyxml.h:746
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
Definition: tinyxml.cpp:1211
TiXmlAttribute * next
Definition: tinyxml.h:835
TiXmlAttribute * Previous()
Definition: tinyxml.h:804
void SetName(const char *_name)
Set the name of this attribute.
Definition: tinyxml.h:785
void SetValue(const std::string &_value)
STL std::string form.
Definition: tinyxml.h:794
bool operator>(const TiXmlAttribute &rhs) const
Definition: tinyxml.h:810
TiXmlAttribute()
Construct an empty attribute.
Definition: tinyxml.h:739
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:763
TiXmlAttribute(const TiXmlAttribute &)
bool operator<(const TiXmlAttribute &rhs) const
Definition: tinyxml.h:809
const std::string & ValueStr() const
Return the value of this attribute.
Definition: tinyxml.h:765
TiXmlAttribute * Next()
Definition: tinyxml.h:798
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
Definition: tinyxml.h:755
TiXmlAttribute * prev
Definition: tinyxml.h:834
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:786
void operator=(const TiXmlAttribute &base)
int QueryIntValue(int *_value) const
QueryIntValue examines the value string.
Definition: tinyxml.cpp:1204
TIXML_STRING name
Definition: tinyxml.h:832
TiXmlBase is a base class for every class in TinyXml.
Definition: tinyxml.h:170
void operator=(const TiXmlBase &base)
int Row() const
Return the position, in the original source file, of this node or attribute.
Definition: tinyxml.h:219
static bool StreamTo(std::istream *in, int character, TIXML_STRING *tag)
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
static bool condenseWhiteSpace
Definition: tinyxml.h:386
static const char * ReadText(const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding)
friend class TiXmlNode
Definition: tinyxml.h:171
static const char * GetEntity(const char *in, char *value, int *length, TiXmlEncoding encoding)
void * userData
Field containing a generic user pointer.
Definition: tinyxml.h:349
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
Definition: tinyxml.h:199
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
static bool IsWhiteSpace(char c)
Definition: tinyxml.h:265
TiXmlBase(const TiXmlBase &)
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
TiXmlCursor location
Definition: tinyxml.h:346
void SetUserData(void *user)
Set a pointer to arbitrary user data.
Definition: tinyxml.h:222
static const int utf8ByteTable[256]
Definition: tinyxml.h:228
static Entity entity[NUM_ENTITY]
Definition: tinyxml.h:385
static bool IsWhiteSpace(int c)
Definition: tinyxml.h:269
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
Expands entities in a string.
Definition: tinyxml.cpp:44
virtual void Print(FILE *cfile, int depth) const =0
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding)
static const char * GetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)
Definition: tinyxml.h:300
int Column() const
See Row()
Definition: tinyxml.h:220
static bool StreamWhiteSpace(std::istream *in, TIXML_STRING *tag)
void * GetUserData()
Get a pointer to arbitrary user data.
Definition: tinyxml.h:223
static const char * errorString[TIXML_ERROR_STRING_COUNT]
Definition: tinyxml.h:344
virtual ~TiXmlBase()
Definition: tinyxml.h:177
@ TIXML_ERROR_DOCUMENT_EMPTY
Definition: tinyxml.h:253
@ TIXML_ERROR_DOCUMENT_TOP_ONLY
Definition: tinyxml.h:256
@ TIXML_ERROR_PARSING_ELEMENT
Definition: tinyxml.h:244
@ TIXML_ERROR_OPENING_FILE
Definition: tinyxml.h:243
@ TIXML_ERROR_READING_END_TAG
Definition: tinyxml.h:249
@ TIXML_ERROR_STRING_COUNT
Definition: tinyxml.h:258
@ TIXML_ERROR_EMBEDDED_NULL
Definition: tinyxml.h:254
@ TIXML_ERROR_PARSING_EMPTY
Definition: tinyxml.h:248
@ TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME
Definition: tinyxml.h:245
@ TIXML_ERROR_PARSING_COMMENT
Definition: tinyxml.h:251
@ TIXML_ERROR_READING_ATTRIBUTES
Definition: tinyxml.h:247
@ TIXML_ERROR_PARSING_UNKNOWN
Definition: tinyxml.h:250
@ TIXML_ERROR_PARSING_DECLARATION
Definition: tinyxml.h:252
@ TIXML_ERROR_READING_ELEMENT_VALUE
Definition: tinyxml.h:246
@ TIXML_ERROR_PARSING_CDATA
Definition: tinyxml.h:255
static const char * ReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
static int ToLower(int v, TiXmlEncoding encoding)
Definition: tinyxml.h:355
const void * GetUserData() const
Get a pointer to arbitrary user data.
Definition: tinyxml.h:224
static void SetCondenseWhiteSpace(bool condense)
The world does not agree on whether white space should be kept or not.
Definition: tinyxml.h:196
An XML comment.
Definition: tinyxml.h:1099
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual ~TiXmlComment()
Definition: tinyxml.h:1110
void CopyTo(TiXmlComment *target) const
Definition: tinyxml.cpp:1276
virtual TiXmlNode * Clone() const
Returns a copy of this Comment.
Definition: tinyxml.cpp:1288
TiXmlComment(const char *_value)
Construct a comment from text.
Definition: tinyxml.h:1104
virtual const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1122
virtual TiXmlComment * ToComment()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1123
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition: tinyxml.cpp:1265
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1282
TiXmlComment & operator=(const TiXmlComment &base)
Definition: tinyxml.cpp:1257
TiXmlComment()
Constructs an empty comment.
Definition: tinyxml.h:1102
In correct XML the declaration is the first entry in the file.
Definition: tinyxml.h:1216
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition: tinyxml.h:1247
TIXML_STRING standalone
Definition: tinyxml.h:1269
TiXmlDeclaration & operator=(const TiXmlDeclaration &copy)
Definition: tinyxml.cpp:1376
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
Definition: tinyxml.cpp:1384
void CopyTo(TiXmlDeclaration *target) const
Definition: tinyxml.cpp:1406
const char * Version() const
Version. Will return an empty string if none was found.
Definition: tinyxml.h:1237
TIXML_STRING encoding
Definition: tinyxml.h:1268
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
Definition: tinyxml.cpp:1422
const char * Standalone() const
Is this a standalone document?
Definition: tinyxml.h:1241
virtual ~TiXmlDeclaration()
Definition: tinyxml.h:1234
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1254
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1253
const char * Encoding() const
Encoding. Will return an empty string if none was found.
Definition: tinyxml.h:1239
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1416
TiXmlDeclaration()
Construct an empty declaration.
Definition: tinyxml.h:1219
TIXML_STRING version
Definition: tinyxml.h:1267
Always the top level node.
Definition: tinyxml.h:1317
bool LoadFile(const std::string &filename, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxml.h:1352
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition: tinyxml.cpp:928
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given null terminated block of xml data.
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
int ErrorId() const
Generally, you probably want the error string ( ErrorDesc() ).
Definition: tinyxml.h:1387
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1124
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
Definition: tinyxml.cpp:922
int TabSize() const
Definition: tinyxml.h:1425
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1452
TiXmlElement * RootElement()
Definition: tinyxml.h:1372
virtual TiXmlNode * Clone() const
Create an exact duplicate of this node and return it.
Definition: tinyxml.cpp:1102
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition: tinyxml.h:1382
TiXmlDocument()
Create an empty document, that has no name.
Definition: tinyxml.cpp:883
int ErrorCol() const
The column where the error occured. See ErrorRow()
Definition: tinyxml.h:1397
void ClearError()
If you have handled the error, it can be reset with this call.
Definition: tinyxml.h:1430
TiXmlDocument & operator=(const TiXmlDocument &copy)
Definition: tinyxml.cpp:914
const TiXmlElement * RootElement() const
Get the root element – the only top level element – of the document.
Definition: tinyxml.h:1371
TiXmlCursor errorLocation
Definition: tinyxml.h:1470
bool Error() const
If an error occurs, Error will be set to true.
Definition: tinyxml.h:1379
int ErrorRow() const
Returns the location (if known) of the error.
Definition: tinyxml.h:1396
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
virtual ~TiXmlDocument()
Definition: tinyxml.h:1330
bool SaveFile(const std::string &filename) const
< STL std::string version.
Definition: tinyxml.h:1356
void Print() const
Write the document to standard out using formatted printing ("pretty print").
Definition: tinyxml.h:1438
void CopyTo(TiXmlDocument *target) const
Definition: tinyxml.cpp:1083
void SetTabSize(int _tabsize)
SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) to report the correct v...
Definition: tinyxml.h:1423
TIXML_STRING errorDesc
Definition: tinyxml.h:1468
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1451
The element is a container class.
Definition: tinyxml.h:886
const char * Attribute(const char *name) const
Given an attribute name, Attribute() returns the value for the attribute of that name,...
Definition: tinyxml.cpp:564
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
int QueryFloatAttribute(const char *name, float *_value) const
QueryFloatAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.h:939
void RemoveAttribute(const std::string &name)
STL std::string form.
Definition: tinyxml.h:1019
const char * ReadValue(const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)
int QueryIntAttribute(const char *name, int *_value) const
QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer...
Definition: tinyxml.cpp:642
int QueryValueAttribute(const std::string &name, std::string *outValue) const
Definition: tinyxml.h:979
TiXmlAttribute * FirstAttribute()
Definition: tinyxml.h:1022
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1071
TiXmlAttribute * LastAttribute()
Definition: tinyxml.h:1024
TiXmlElement & operator=(const TiXmlElement &base)
Definition: tinyxml.cpp:538
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
Definition: tinyxml.cpp:859
void RemoveAttribute(const char *name)
Deletes an attribute with the given name.
Definition: tinyxml.cpp:429
virtual ~TiXmlElement()
Definition: tinyxml.cpp:546
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1070
int QueryStringAttribute(const char *name, std::string *_value) const
QueryStringAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.h:949
void SetDoubleAttribute(const std::string &name, double value)
Definition: tinyxml.cpp:743
const char * GetText() const
Convenience function for easy access to the text inside an element.
Definition: tinyxml.cpp:870
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition: tinyxml.cpp:770
const TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
Definition: tinyxml.h:1023
TiXmlAttributeSet attributeSet
Definition: tinyxml.h:1092
void CopyTo(TiXmlElement *target) const
Definition: tinyxml.cpp:823
int QueryBoolAttribute(const char *name, bool *_value) const
QueryBoolAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.cpp:664
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:845
void SetAttribute(const char *name, const char *_value)
Sets an attribute of name to a given value.
Definition: tinyxml.cpp:752
int QueryUnsignedAttribute(const char *name, unsigned *_value) const
QueryUnsignedAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.cpp:651
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
Definition: tinyxml.h:1021
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.cpp:698
int QueryValueAttribute(const std::string &name, T *outValue) const
Template form of the attribute query which will try to read the attribute into the specified type.
Definition: tinyxml.h:966
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
Definition: tinyxml.h:1556
TiXmlHandle FirstChild() const
Return a handle to the first child node.
Definition: tinyxml.cpp:1589
TiXmlHandle ChildElement(const char *value, int index) const
Return a handle to the "index" child element with the given name.
Definition: tinyxml.cpp:1694
TiXmlText * ToText() const
Return the handle as a TiXmlText.
Definition: tinyxml.h:1606
TiXmlNode * ToNode() const
Return the handle as a TiXmlNode.
Definition: tinyxml.h:1600
TiXmlHandle Child(const char *value, int index) const
Return a handle to the "index" child with the given name.
Definition: tinyxml.cpp:1656
TiXmlNode * Node() const
Definition: tinyxml.h:1614
TiXmlText * Text() const
Definition: tinyxml.h:1622
TiXmlElement * ToElement() const
Return the handle as a TiXmlElement.
Definition: tinyxml.h:1603
TiXmlUnknown * Unknown() const
Definition: tinyxml.h:1626
TiXmlNode * node
Definition: tinyxml.h:1629
TiXmlHandle FirstChildElement(const std::string &_value) const
Definition: tinyxml.h:1593
TiXmlUnknown * ToUnknown() const
Return the handle as a TiXmlUnknown.
Definition: tinyxml.h:1609
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml.h:1559
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
Definition: tinyxml.cpp:1613
TiXmlElement * Element() const
Definition: tinyxml.h:1618
TiXmlHandle FirstChild(const std::string &_value) const
Definition: tinyxml.h:1592
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
Definition: tinyxml.h:1561
TiXmlHandle operator=(const TiXmlHandle &ref)
Definition: tinyxml.h:1562
TiXmlHandle ChildElement(const std::string &_value, int index) const
Definition: tinyxml.h:1596
TiXmlHandle Child(const std::string &_value, int index) const
Definition: tinyxml.h:1595
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:397
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
Definition: tinyxml.cpp:178
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:664
TiXmlDocument * GetDocument()
Definition: tinyxml.h:646
TiXmlElement * FirstChildElement()
Definition: tinyxml.h:623
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:488
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cpp:222
TiXmlNode * FirstChild(const char *_value)
The first child of this node with the matching 'value'. Will be null if none found.
Definition: tinyxml.h:492
TiXmlElement * FirstChildElement(const std::string &_value)
STL std::string form.
Definition: tinyxml.h:634
const TiXmlElement * NextSiblingElement(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:618
TiXmlNode * NextSibling(const char *_next)
Definition: tinyxml.h:596
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:663
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cpp:255
const TiXmlNode * Parent() const
Definition: tinyxml.h:486
const TiXmlElement * FirstChildElement(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:633
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:576
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
Definition: tinyxml.h:457
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
Definition: tinyxml.cpp:377
virtual ~TiXmlNode()
Definition: tinyxml.cpp:139
TIXML_STRING value
Definition: tinyxml.h:715
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
TiXmlNode * PreviousSibling()
Definition: tinyxml.h:577
TiXmlNode * LastChild(const std::string &_value)
STL std::string form.
Definition: tinyxml.h:508
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:660
void operator=(const TiXmlNode &base)
const TiXmlNode * LastChild() const
Definition: tinyxml.h:497
NodeType type
Definition: tinyxml.h:710
TiXmlElement * NextSiblingElement(const char *_next)
Definition: tinyxml.h:614
TiXmlNode * Parent()
One step up the DOM.
Definition: tinyxml.h:485
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:591
TiXmlNode * LastChild()
The last child of this node. Will be null if there are no children.
Definition: tinyxml.h:498
int Type() const
Query the type (as an enumerated value, above) of this node.
Definition: tinyxml.h:640
void CopyTo(TiXmlNode *target) const
Definition: tinyxml.cpp:153
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml.h:651
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:661
TiXmlNode * prev
Definition: tinyxml.h:717
TiXmlNode * FirstChild()
Definition: tinyxml.h:489
TiXmlElement * FirstChildElement(const char *_value)
Definition: tinyxml.h:629
const TiXmlNode * IterateChildren(const std::string &_value, const TiXmlNode *previous) const
STL std::string form.
Definition: tinyxml.h:537
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:587
TiXmlNode * FirstChild(const std::string &_value)
STL std::string form.
Definition: tinyxml.h:506
TiXmlNode * IterateChildren(const TiXmlNode *previous)
Definition: tinyxml.h:527
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:656
TiXmlElement * NextSiblingElement()
Definition: tinyxml.h:605
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
TiXmlElement * NextSiblingElement(const std::string &_value)
STL std::string form.
Definition: tinyxml.h:619
friend std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)
An output stream operator, for every class.
Definition: tinyxml.cpp:1566
TiXmlNode * parent
Definition: tinyxml.h:709
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:657
virtual const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:655
TiXmlNode * next
Definition: tinyxml.h:718
virtual TiXmlComment * ToComment()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:662
TiXmlNode * LastChild(const char *_value)
The last child of this node matching 'value'. Will be null if there are no children.
Definition: tinyxml.h:501
TiXmlNode * firstChild
Definition: tinyxml.h:712
void SetValue(const std::string &_value)
STL std::string form.
Definition: tinyxml.h:479
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:654
TiXmlNode * lastChild
Definition: tinyxml.h:713
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
Definition: tinyxml.cpp:471
void Clear()
Delete all the children of this node. Does not affect 'this'.
Definition: tinyxml.cpp:161
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
Definition: tinyxml.cpp:288
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
Definition: tinyxml.cpp:501
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:665
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
Definition: tinyxml.cpp:327
friend std::istream & operator>>(std::istream &in, TiXmlNode &base)
An input stream operator, for every class.
Definition: tinyxml.cpp:1555
friend class TiXmlElement
Definition: tinyxml.h:399
TiXmlNode(const TiXmlNode &)
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:658
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cpp:206
TiXmlNode * NextSibling(const std::string &_value)
STL std::string form.
Definition: tinyxml.h:588
TiXmlNode * NextSibling()
Definition: tinyxml.h:592
NodeType
The types of XML nodes supported by TinyXml.
Definition: tinyxml.h:433
TiXmlNode * PreviousSibling(const char *_prev)
Definition: tinyxml.h:581
const std::string & ValueStr() const
Return Value() as a std::string.
Definition: tinyxml.h:463
TiXmlNode * IterateChildren(const std::string &_value, const TiXmlNode *previous)
STL std::string form.
Definition: tinyxml.h:538
const TiXmlNode * FirstChild(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:505
void SetValue(const char *_value)
Changes the value of the node.
Definition: tinyxml.h:476
const TIXML_STRING & ValueTStr() const
Definition: tinyxml.h:465
const TiXmlNode * PreviousSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:585
const TiXmlNode * LastChild(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:507
TiXmlNode * IterateChildren(const char *_value, const TiXmlNode *previous)
Definition: tinyxml.h:533
TiXmlNode * PreviousSibling(const std::string &_value)
STL std::string form.
Definition: tinyxml.h:586
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cpp:441
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:653
Print to memory functionality.
Definition: tinyxml.h:1653
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
Definition: tinyxml.cpp:1814
const char * Indent()
Query the indention string.
Definition: tinyxml.h:1674
TIXML_STRING buffer
Definition: tinyxml.h:1708
void SetIndent(const char *_indent)
Set the indent characters for printing.
Definition: tinyxml.h:1672
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
Definition: tinyxml.cpp:1718
void SetStreamPrinting()
Switch over to "stream printing" which is the most dense formatting without linebreaks.
Definition: tinyxml.h:1686
void SetLineBreak(const char *_lineBreak)
Set the line breaking string.
Definition: tinyxml.h:1679
size_t Size()
Return the length of the result string.
Definition: tinyxml.h:1692
const char * CStr()
Return the result.
Definition: tinyxml.h:1690
TIXML_STRING lineBreak
Definition: tinyxml.h:1710
const std::string & Str()
Return the result.
Definition: tinyxml.h:1695
const char * LineBreak()
Query the current line breaking string.
Definition: tinyxml.h:1681
TIXML_STRING indent
Definition: tinyxml.h:1709
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
Definition: tinyxml.cpp:1713
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1182
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
void SetCDATA(bool _cdata)
Turns on or off a CDATA representation of text.
Definition: tinyxml.h:1177
TiXmlText(const char *initValue)
Constructor for text element.
Definition: tinyxml.h:1154
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1328
TiXmlText & operator=(const TiXmlText &base)
Definition: tinyxml.h:1169
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
Definition: tinyxml.cpp:1334
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1181
TiXmlText(const std::string &initValue)
Constructor.
Definition: tinyxml.h:1162
virtual ~TiXmlText()
Definition: tinyxml.h:1159
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition: tinyxml.cpp:1300
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
void CopyTo(TiXmlText *target) const
Definition: tinyxml.cpp:1321
bool CDATA() const
Queries whether this represents text using a CDATA section.
Definition: tinyxml.h:1175
TiXmlText(const TiXmlText &copy)
Definition: tinyxml.h:1168
Any tag that tinyXml doesn't recognize is saved as an unknown.
Definition: tinyxml.h:1281
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1297
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
Definition: tinyxml.cpp:1448
virtual ~TiXmlUnknown()
Definition: tinyxml.h:1284
TiXmlUnknown & operator=(const TiXmlUnknown &copy)
Definition: tinyxml.h:1287
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
Definition: tinyxml.cpp:1454
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1296
TiXmlUnknown(const TiXmlUnknown &copy)
Definition: tinyxml.h:1286
void CopyTo(TiXmlUnknown *target) const
Definition: tinyxml.cpp:1442
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition: tinyxml.cpp:1434
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
Implements the interface to the "Visitor pattern" (see the Accept() method.) If you call the Accept()...
Definition: tinyxml.h:104
virtual ~TiXmlVisitor()
Definition: tinyxml.h:106
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
Definition: tinyxml.h:119
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
Definition: tinyxml.h:111
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
Definition: tinyxml.h:109
virtual bool Visit(const TiXmlText &)
Visit a text node.
Definition: tinyxml.h:121
virtual bool VisitExit(const TiXmlElement &)
Visit an element.
Definition: tinyxml.h:116
virtual bool Visit(const TiXmlUnknown &)
Visit an unknown node.
Definition: tinyxml.h:125
virtual bool VisitEnter(const TiXmlElement &, const TiXmlAttribute *)
Visit an element.
Definition: tinyxml.h:114
virtual bool Visit(const TiXmlComment &)
Visit a comment node.
Definition: tinyxml.h:123
const int TIXML_PATCH_VERSION
Definition: tinyxml.h:69
const int TIXML_MAJOR_VERSION
Definition: tinyxml.h:67
const int TIXML_MINOR_VERSION
Definition: tinyxml.h:68
TiXmlEncoding
Definition: tinyxml.h:139
@ TIXML_ENCODING_UNKNOWN
Definition: tinyxml.h:140
@ TIXML_ENCODING_LEGACY
Definition: tinyxml.h:142
@ TIXML_ENCODING_UTF8
Definition: tinyxml.h:141
@ TIXML_WRONG_TYPE
Definition: tinyxml.h:133
@ TIXML_SUCCESS
Definition: tinyxml.h:131
@ TIXML_NO_ATTRIBUTE
Definition: tinyxml.h:132
const TiXmlEncoding TIXML_DEFAULT_ENCODING
Definition: tinyxml.h:145
unsigned int strLength
Definition: tinyxml.h:376
#define TIXML_STRING
Definition: tinyxml.h:36