TinyXml is a compact library that implements XML Parsing and Manipulation.

Dependents:   tinyxml_test

Committer:
wvd_vegt
Date:
Mon Apr 18 18:54:09 2011 +0000
Revision:
0:3c1d63c20cfc
First Version

Who changed what in which revision?

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