34 FILE*
TiXmlFOpen(
const char* filename,
const char* mode );
39 FILE*
TiXmlFOpen(
const char* filename,
const char* mode )
41 return fopen( filename, mode );
48 while( i<(
int)str.length() )
50 unsigned char c = (
unsigned char) str[i];
53 && i < ( (
int)str.length() - 2 )
67 while ( i<(
int)str.length()-1 )
69 outString->append( str.c_str() + i, 1 );
106 #if defined(TIXML_SNPRINTF)
107 TIXML_SNPRINTF( buf,
sizeof(buf),
"&#x%02X;", (
unsigned) ( c & 0xff ) );
109 sprintf( buf,
"&#x%02X;", (
unsigned) ( c & 0xff ) );
114 outString->append( buf, (
int)strlen( buf ) );
121 *outString += (char) c;
224 if ( !beforeThis || beforeThis->
parent !=
this ) {
239 node->
next = beforeThis;
241 if ( beforeThis->
prev )
250 beforeThis->
prev = node;
257 if ( !afterThis || afterThis->
parent !=
this ) {
272 node->
prev = afterThis;
274 if ( afterThis->
next )
283 afterThis->
next = node;
293 if ( replaceThis->
parent !=
this )
311 if ( replaceThis->
next )
316 if ( replaceThis->
prev )
333 if ( removeThis->
parent !=
this )
339 if ( removeThis->
next )
344 if ( removeThis->
prev )
358 if ( strcmp( node->
Value(), _value ) == 0 )
370 if ( strcmp( node->
Value(), _value ) == 0 )
385 assert( previous->
parent ==
this );
399 assert( previous->
parent ==
this );
408 for ( node =
next; node; node = node->
next )
410 if ( strcmp( node->
Value(), _value ) == 0 )
420 for ( node =
prev; node; node = node->
prev )
422 if ( strcmp( node->
Value(), _value ) == 0 )
505 for( node =
this; node; node = node->
parent )
568 return node->
Value();
585 const char* result = 0;
588 result = attrib->
Value();
600 const std::string* result = 0;
615 const char* result = 0;
618 result = attrib->
Value();
630 const std::string* result = 0;
659 *
value = (unsigned)ival;
774 for ( i=0; i<depth; i++ ) {
775 fprintf( cfile,
" " );
778 fprintf( cfile,
"<%s",
value.c_str() );
783 fprintf( cfile,
" " );
784 attrib->
Print( cfile, depth );
794 fprintf( cfile,
" />" );
798 fprintf( cfile,
">" );
800 fprintf( cfile,
"</%s>",
value.c_str() );
804 fprintf( cfile,
">" );
810 fprintf( cfile,
"\n" );
812 node->
Print( cfile, depth+1 );
814 fprintf( cfile,
"\n" );
815 for( i=0; i<depth; ++i ) {
816 fprintf( cfile,
" " );
818 fprintf( cfile,
"</%s>",
value.c_str() );
833 attribute = attribute->
Next() )
851 if ( !node->Accept( visitor ) )
876 return childText->
Value();
894 value = documentName;
903 value = documentName;
943 bool result =
LoadFile( file, encoding );
968 fseek( file, 0, SEEK_END );
969 length = ftell( file );
970 fseek( file, 0, SEEK_SET );
1000 char* buf =
new char[ length+1 ];
1003 if ( fread( buf, length, 1, file ) != 1 ) {
1020 const char* p = buf;
1022 const char CR = 0x0d;
1023 const char LF = 0x0a;
1027 assert( p < (buf+length) );
1028 assert( q <= (buf+length) );
1042 assert( q <= (buf+length) );
1045 Parse( buf, 0, encoding );
1079 return (ferror(fp) == 0);
1118 node->Print( cfile, depth );
1119 fprintf( cfile,
"\n" );
1130 if ( !node->Accept( visitor ) )
1185 if (
value.find (
'\"') == TIXML_STRING::npos) {
1187 fprintf (cfile,
"%s=\"%s\"", n.c_str(), v.c_str() );
1190 (*str) += n; (*str) +=
"=\""; (*str) += v; (*str) +=
"\"";
1195 fprintf (cfile,
"%s='%s'", n.c_str(), v.c_str() );
1198 (*str) += n; (*str) +=
"='"; (*str) += v; (*str) +=
"'";
1221 #if defined(TIXML_SNPRINTF)
1224 sprintf (buf,
"%d", _value);
1232 #if defined(TIXML_SNPRINTF)
1235 sprintf (buf,
"%g", _value);
1242 return atoi (
value.c_str ());
1247 return atof (
value.c_str ());
1268 for (
int i=0; i<depth; i++ )
1270 fprintf( cfile,
" " );
1272 fprintf( cfile,
"<!--%s-->",
value.c_str() );
1284 return visitor->
Visit( *
this );
1306 fprintf( cfile,
"\n" );
1307 for ( i=0; i<depth; i++ ) {
1308 fprintf( cfile,
" " );
1310 fprintf( cfile,
"<![CDATA[%s]]>\n",
value.c_str() );
1316 fprintf( cfile,
"%s", buffer.c_str() );
1330 return visitor->
Visit( *
this );
1348 const char * _encoding,
1349 const char * _standalone )
1359 const std::string& _encoding,
1360 const std::string& _standalone )
1386 if ( cfile ) fprintf( cfile,
"<?xml " );
1387 if ( str ) (*str) +=
"<?xml ";
1390 if ( cfile ) fprintf (cfile,
"version=\"%s\" ",
version.c_str ());
1391 if ( str ) { (*str) +=
"version=\""; (*str) +=
version; (*str) +=
"\" "; }
1394 if ( cfile ) fprintf (cfile,
"encoding=\"%s\" ",
encoding.c_str ());
1395 if ( str ) { (*str) +=
"encoding=\""; (*str) +=
encoding; (*str) +=
"\" "; }
1398 if ( cfile ) fprintf (cfile,
"standalone=\"%s\" ",
standalone.c_str ());
1399 if ( str ) { (*str) +=
"standalone=\""; (*str) +=
standalone; (*str) +=
"\" "; }
1401 if ( cfile ) fprintf( cfile,
"?>" );
1402 if ( str ) (*str) +=
"?>";
1418 return visitor->
Visit( *
this );
1436 for (
int i=0; i<depth; i++ )
1437 fprintf( cfile,
" " );
1438 fprintf( cfile,
"<%s>",
value.c_str() );
1450 return visitor->
Visit( *
this );
1497 if ( node == removeMe )
1514 if ( node->name == name )
1536 if ( strcmp( node->name.c_str(), name ) == 0 )
1558 tag.reserve( 8 * 1000 );
1571 out << printer.
Str();
1582 out.append( printer.
Str() );
1729 for(
const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->
Next() )
1732 attrib->Print( 0, 0, &
buffer );
void Remove(TiXmlAttribute *attribute)
TiXmlAttribute * Find(const char *_name) const
void Add(TiXmlAttribute *attribute)
const TiXmlAttribute * First() const
TiXmlAttribute * FindOrCreate(const char *_name)
An attribute is a name-value pair.
void SetIntValue(int _value)
Set the value from an integer.
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
double DoubleValue() const
Return the value of this attribute, converted to a double.
int IntValue() const
Return the value of this attribute, converted to an integer.
const char * Value() const
Return the value of this attribute.
void SetDoubleValue(double _value)
Set the value from a double.
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
void SetName(const char *_name)
Set the name of this attribute.
const char * Name() const
Return the name of this attribute.
const std::string & ValueStr() const
Return the value of this attribute.
void SetValue(const char *_value)
Set the value.
int QueryIntValue(int *_value) const
QueryIntValue examines the value string.
TiXmlBase is a base class for every class in TinyXml.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
static bool condenseWhiteSpace
void * userData
Field containing a generic user pointer.
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
static Entity entity[NUM_ENTITY]
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
Expands entities in a string.
virtual void Print(FILE *cfile, int depth) const =0
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
@ TIXML_ERROR_DOCUMENT_EMPTY
@ TIXML_ERROR_DOCUMENT_TOP_ONLY
@ TIXML_ERROR_OPENING_FILE
In correct XML the declaration is the first entry in the file.
TiXmlDeclaration & operator=(const TiXmlDeclaration ©)
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
void CopyTo(TiXmlDeclaration *target) const
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
TiXmlDeclaration()
Construct an empty declaration.
Always the top level node.
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given null terminated block of xml data.
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
virtual TiXmlNode * Clone() const
Create an exact duplicate of this node and return it.
TiXmlDocument()
Create an empty document, that has no name.
void ClearError()
If you have handled the error, it can be reset with this call.
TiXmlDocument & operator=(const TiXmlDocument ©)
TiXmlCursor errorLocation
bool Error() const
If an error occurs, Error will be set to true.
void Print() const
Write the document to standard out using formatted printing ("pretty print").
void CopyTo(TiXmlDocument *target) const
The element is a container class.
const char * Attribute(const char *name) const
Given an attribute name, Attribute() returns the value for the attribute of that name,...
int QueryIntAttribute(const char *name, int *_value) const
QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer...
TiXmlElement & operator=(const TiXmlElement &base)
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
void RemoveAttribute(const char *name)
Deletes an attribute with the given name.
void SetDoubleAttribute(const std::string &name, double value)
const char * GetText() const
Convenience function for easy access to the text inside an element.
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
TiXmlAttributeSet attributeSet
void CopyTo(TiXmlElement *target) const
int QueryBoolAttribute(const char *name, bool *_value) const
QueryBoolAttribute examines the attribute - see QueryIntAttribute().
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
void SetAttribute(const char *name, const char *_value)
Sets an attribute of name to a given value.
int QueryUnsignedAttribute(const char *name, unsigned *_value) const
QueryUnsignedAttribute examines the attribute - see QueryIntAttribute().
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
TiXmlHandle FirstChild() const
Return a handle to the first child node.
TiXmlHandle ChildElement(const char *value, int index) const
Return a handle to the "index" child element with the given name.
TiXmlHandle Child(const char *value, int index) const
Return a handle to the "index" child with the given name.
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
The parent class for everything in the Document Object Model.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
const TiXmlNode * LastChild() const
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
int Type() const
Query the type (as an enumerated value, above) of this node.
void CopyTo(TiXmlNode *target) const
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
void Clear()
Delete all the children of this node. Does not affect 'this'.
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
friend class TiXmlElement
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
NodeType
The types of XML nodes supported by TinyXml.
void SetValue(const char *_value)
Changes the value of the node.
const TIXML_STRING & ValueTStr() const
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
Print to memory functionality.
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
void SetStreamPrinting()
Switch over to "stream printing" which is the most dense formatting without linebreaks.
const std::string & Str()
Return the result.
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
TiXmlText(const char *initValue)
Constructor for text element.
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
void CopyTo(TiXmlText *target) const
bool CDATA() const
Queries whether this represents text using a CDATA section.
Any tag that tinyXml doesn't recognize is saved as an unknown.
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
void CopyTo(TiXmlUnknown *target) const
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Implements the interface to the "Visitor pattern" (see the Accept() method.) If you call the Accept()...
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
std::istream & operator>>(std::istream &in, TiXmlNode &base)
std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)
const TiXmlEncoding TIXML_DEFAULT_ENCODING
FILE * TiXmlFOpen(const char *filename, const char *mode)
const unsigned char TIXML_UTF_LEAD_0
const unsigned char TIXML_UTF_LEAD_1
const unsigned char TIXML_UTF_LEAD_2