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