46 while( i<(
int)str.length() )
48 unsigned char c = (
unsigned char) str[i];
51 && i < ( (
int)str.length() - 2 )
65 while ( i<(
int)str.length()-1 )
67 outString->append( str.c_str() + i, 1 );
104 #if defined(TIXML_SNPRINTF)
105 TIXML_SNPRINTF( buf,
sizeof(buf),
"&#x%02X;", (
unsigned) ( c & 0xff ) );
107 sprintf( buf,
"&#x%02X;", (
unsigned) ( c & 0xff ) );
112 outString->append( buf, (
int)strlen( buf ) );
119 *outString += (char) c;
219 if ( !beforeThis || beforeThis->
parent !=
this ) {
233 node->
next = beforeThis;
235 if ( beforeThis->
prev )
244 beforeThis->
prev = node;
251 if ( !afterThis || afterThis->
parent !=
this ) {
265 node->
prev = afterThis;
267 if ( afterThis->
next )
276 afterThis->
next = node;
283 if ( replaceThis->
parent !=
this )
293 if ( replaceThis->
next )
298 if ( replaceThis->
prev )
311 if ( removeThis->
parent !=
this )
317 if ( removeThis->
next )
322 if ( removeThis->
prev )
336 if ( strcmp( node->
Value(), _value ) == 0 )
348 if ( strcmp( node->
Value(), _value ) == 0 )
363 assert( previous->
parent ==
this );
377 assert( previous->
parent ==
this );
386 for ( node =
next; node; node = node->
next )
388 if ( strcmp( node->
Value(), _value ) == 0 )
398 for ( node =
prev; node; node = node->
prev )
400 if ( strcmp( node->
Value(), _value ) == 0 )
486 for( node =
this; node; node = node->
parent )
550 return node->
Value();
589 *i = atoi( s->
c_str() );
623 *d = atof( s->
c_str() );
677 #if defined(TIXML_SNPRINTF)
678 TIXML_SNPRINTF( buf,
sizeof(buf),
"%d", val );
680 sprintf( buf,
"%d", val );
699 #if defined(TIXML_SNPRINTF)
700 TIXML_SNPRINTF( buf,
sizeof(buf),
"%f", val );
702 sprintf( buf,
"%f", val );
714 const char* _name = cname;
715 const char* _value = cvalue;
766 for ( i=0; i<depth; i++ ) {
767 fprintf( cfile,
" " );
770 fprintf( cfile,
"<%s",
value.c_str() );
775 fprintf( cfile,
" " );
776 attrib->Print( cfile, depth );
786 fprintf( cfile,
" />" );
790 fprintf( cfile,
">" );
792 fprintf( cfile,
"</%s>",
value.c_str() );
796 fprintf( cfile,
">" );
802 fprintf( cfile,
"\n" );
804 node->
Print( cfile, depth+1 );
806 fprintf( cfile,
"\n" );
807 for( i=0; i<depth; ++i ) {
808 fprintf( cfile,
" " );
810 fprintf( cfile,
"</%s>",
value.c_str() );
825 attribute = attribute->
Next() )
843 if ( !node->Accept( visitor ) )
868 return childText->
Value();
886 value = documentName;
896 value = documentName;
949 FILE* file = fopen(
value.c_str (),
"rb" );
953 bool result =
LoadFile( file, encoding );
978 fseek( file, 0, SEEK_END );
979 length = ftell( file );
980 fseek( file, 0, SEEK_SET );
990 else if( length < 0 )
999 data.reserve( length );
1022 char* buf =
new char[ length+1 ];
1025 if ( fread( buf, length, 1, file ) != 1 ) {
1031 const char* lastPos = buf;
1032 const char* p = buf;
1036 assert( p < (buf+length) );
1040 data.append( lastPos, (p-lastPos+1) );
1043 assert( p <= (buf+length) );
1045 else if ( *p == 0xd ) {
1048 if ( (p-lastPos) > 0 ) {
1049 data.append( lastPos, p-lastPos );
1053 if ( *(p+1) == 0xa ) {
1057 assert( p <= (buf+length) );
1063 assert( p <= (buf+length) );
1072 data.append( lastPos, p-lastPos );
1077 Parse( data.c_str(), 0, encoding );
1089 FILE* fp = fopen( filename,
"w" );
1108 fputc( TIXML_UTF_LEAD_0, fp );
1109 fputc( TIXML_UTF_LEAD_1, fp );
1110 fputc( TIXML_UTF_LEAD_2, fp );
1113 return (ferror(fp) == 0);
1148 node->
Print( cfile, depth );
1149 fprintf( cfile,
"\n" );
1160 if ( !node->Accept( visitor ) )
1215 if (
value.find (
'\"') == TIXML_STRING::npos) {
1217 fprintf (cfile,
"%s=\"%s\"", n.c_str(), v.c_str() );
1220 (*str) += n; (*str) +=
"=\""; (*str) += v; (*str) +=
"\"";
1225 fprintf (cfile,
"%s='%s'", n.c_str(), v.c_str() );
1228 (*str) += n; (*str) +=
"='"; (*str) += v; (*str) +=
"'";
1236 if ( sscanf(
value.c_str(),
"%d", ival ) == 1 )
1243 if ( sscanf(
value.c_str(),
"%lf", dval ) == 1 )
1251 #if defined(TIXML_SNPRINTF)
1252 TIXML_SNPRINTF(buf,
sizeof(buf),
"%d", _value);
1254 sprintf (buf,
"%d", _value);
1262 #if defined(TIXML_SNPRINTF)
1263 TIXML_SNPRINTF( buf,
sizeof(buf),
"%lf", _value);
1265 sprintf (buf,
"%lf", _value);
1272 return atoi (
value.c_str ());
1277 return atof (
value.c_str ());
1297 for (
int i=0; i<depth; i++ )
1299 fprintf( cfile,
" " );
1301 fprintf( cfile,
"<!--%s-->",
value.c_str() );
1313 return visitor->
Visit( *
this );
1335 fprintf( cfile,
"\n" );
1336 for ( i=0; i<depth; i++ ) {
1337 fprintf( cfile,
" " );
1339 fprintf( cfile,
"<![CDATA[%s]]>\n",
value.c_str() );
1345 fprintf( cfile,
"%s", buffer.c_str() );
1359 return visitor->
Visit( *
this );
1377 const char * _encoding,
1378 const char * _standalone )
1387 #ifdef TIXML_USE_STL
1416 if ( cfile ) fprintf( cfile,
"<?xml " );
1417 if ( str ) (*str) +=
"<?xml ";
1420 if ( cfile ) fprintf (cfile,
"version=\"%s\" ",
version.c_str ());
1421 if ( str ) { (*str) +=
"version=\""; (*str) +=
version; (*str) +=
"\" "; }
1424 if ( cfile ) fprintf (cfile,
"encoding=\"%s\" ",
encoding.c_str ());
1425 if ( str ) { (*str) +=
"encoding=\""; (*str) +=
encoding; (*str) +=
"\" "; }
1428 if ( cfile ) fprintf (cfile,
"standalone=\"%s\" ",
standalone.c_str ());
1429 if ( str ) { (*str) +=
"standalone=\""; (*str) +=
standalone; (*str) +=
"\" "; }
1431 if ( cfile ) fprintf( cfile,
"?>" );
1432 if ( str ) (*str) +=
"?>";
1448 return visitor->
Visit( *
this );
1466 for (
int i=0; i<depth; i++ )
1467 fprintf( cfile,
" " );
1468 fprintf( cfile,
"<%s>",
value.c_str() );
1480 return visitor->
Visit( *
this );
1512 #ifdef TIXML_USE_STL
1531 if ( node == removeMe )
1544 #ifdef TIXML_USE_STL
1549 if ( node->
name == name )
1573 if ( strcmp( node->
name.c_str(), name ) == 0 )
1591 #ifdef TIXML_USE_STL
1595 tag.reserve( 8 * 1000 );
1604 #ifdef TIXML_USE_STL
1610 out << printer.
Str();
1644 TiXmlNode* child = node->FirstChild( value );
1668 TiXmlElement* child = node->FirstChildElement( value );
1700 TiXmlNode* child = node->FirstChild( value );
1738 TiXmlElement* child = node->FirstChildElement( value );
1768 for(
const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->
Next() )
const TiXmlAttribute * First() const
An attribute is a name-value pair.
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
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.
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks...
const unsigned char TIXML_UTF_LEAD_2
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
bool Error() const
If an error occurs, Error will be set to true.
double DoubleValue() const
Return the value of this attribute, converted to a double.
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
int IntValue() const
Return the value of this attribute, converted to an integer.
TiXmlHandle FirstChild() const
Return a handle to the first child node.
void CopyTo(TiXmlUnknown *target) const
void CopyTo(TiXmlDocument *target) const
int Type() const
Query the type (as an enumerated value, above) of this node.
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
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 operator=(const TiXmlDeclaration ©)
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
void operator=(const TiXmlDocument ©)
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
TiXmlDocument()
Create an empty document, that has no name.
void ClearError()
If you have handled the error, it can be reset with this call.
const char * Value() const
Return the value of this attribute.
int QueryIntValue(int *_value) const
QueryIntValue examines the value string.
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 ...
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
void SetValue(const char *_value)
Changes the value of the node.
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
const unsigned char TIXML_UTF_LEAD_0
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
static bool condenseWhiteSpace
NodeType
The types of XML nodes supported by TinyXml.
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
static void PutString(const TIXML_STRING &str, TIXML_STRING *out)
const TiXmlNode * LastChild() const
const char * Name() const
Return the name of this attribute.
void SetDoubleValue(double _value)
Set the value from a double.
void * userData
Field containing a generic user pointer.
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
const unsigned char TIXML_UTF_LEAD_1
void Print() const
Write the document to standard out using formatted printing ("pretty print").
In correct XML the declaration is the first entry in the file.
TiXmlAttributeSet attributeSet
Any tag that tinyXml doesn't recognize is saved as an unknown.
const TiXmlEncoding TIXML_DEFAULT_ENCODING
TiXmlHandle ChildElement(const char *value, int index) const
Return a handle to the "index" child element with the given name.
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
void RemoveAttribute(const char *name)
Deletes an attribute with the given name.
virtual TiXmlNode * Clone() const
Create an exact duplicate of this node and return it.
void SetAttribute(const char *name, const char *_value)
Sets an attribute of name to a given value.
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 ...
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 ...
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Always the top level node.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
TiXmlElement(const char *in_value)
Construct an element.
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
const TiXmlAttribute * Find(const char *_name) const
static Entity entity[NUM_ENTITY]
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
TiXmlHandle Child(const char *value, int index) const
Return a handle to the "index" child with the given name.
void Add(TiXmlAttribute *attribute)
const std::string & ValueStr() const
Return the value of this attribute.
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
bool CDATA() const
Queries whether this represents text using a CDATA section.
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
TiXmlBase is a base class for every class in TinyXml.
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
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 operator=(const TiXmlElement &base)
int QueryIntAttribute(const char *name, int *_value) const
QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer...
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.
TiXmlNode(NodeType _type)
The parent class for everything in the Document Object Model.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
void CopyTo(TiXmlNode *target) const
void SetIntValue(int _value)
Set the value from an integer.
Print to memory functionality.
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
TiXmlText(const char *initValue)
Constructor for text element.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
void CopyTo(TiXmlText *target) const
void CopyTo(TiXmlElement *target) const
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
const char * GetText() const
Convenience function for easy access to the text inside an element.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
void Remove(TiXmlAttribute *attribute)
void Clear()
Delete all the children of this node. Does not affect 'this'.
void SetValue(const char *_value)
Set the value.
const std::string & Str()
Return the result.
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
TiXmlDeclaration()
Construct an empty declaration.
void SetStreamPrinting()
Switch over to "stream printing" which is the most dense formatting without linebreaks.
const char * Attribute(const char *name) const
Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
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 ...
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
void CopyTo(TiXmlDeclaration *target) const
The element is a container class.
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
std::ostream & operator<<(std::ostream &s, Expression &e)