45 bool TiXmlBase::condenseWhiteSpace =
true;
50 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) 52 errno_t err = fopen_s( &fp, filename, mode );
57 return fopen( filename, mode );
65 while( i<(
int)str.length() )
67 unsigned char c = (
unsigned char) str[i];
70 && i < ( (
int)str.length() - 2 )
84 while ( i<(
int)str.length()-1 )
86 outString->append( str.c_str() +
i, 1 );
94 outString->append( entity[0].str, entity[0].strLength );
99 outString->append( entity[1].str, entity[1].strLength );
104 outString->append( entity[2].str, entity[2].strLength );
107 else if ( c ==
'\"' )
109 outString->append( entity[3].str, entity[3].strLength );
112 else if ( c ==
'\'' )
114 outString->append( entity[4].str, entity[4].strLength );
123 #if defined(TIXML_SNPRINTF) 124 TIXML_SNPRINTF( buf,
sizeof(buf),
"&#x%02X;", (
unsigned) ( c & 0xff ) );
126 sprintf( buf,
"&#x%02X;", (
unsigned) ( c & 0xff ) );
131 outString->append( buf, (
int)strlen( buf ) );
138 *outString += (char) c;
241 if ( !beforeThis || beforeThis->
parent !=
this ) {
256 node->
next = beforeThis;
258 if ( beforeThis->
prev )
267 beforeThis->
prev = node;
274 if ( !afterThis || afterThis->
parent !=
this ) {
289 node->
prev = afterThis;
291 if ( afterThis->
next )
300 afterThis->
next = node;
310 if ( replaceThis->
parent !=
this )
328 if ( replaceThis->
next )
333 if ( replaceThis->
prev )
350 if ( removeThis->
parent !=
this )
356 if ( removeThis->
next )
361 if ( removeThis->
prev )
375 if ( strcmp( node->
Value(), _value ) == 0 )
387 if ( strcmp( node->
Value(), _value ) == 0 )
402 assert( previous->
parent ==
this );
416 assert( previous->
parent ==
this );
425 for ( node =
next; node; node = node->
next )
427 if ( strcmp( node->
Value(), _value ) == 0 )
437 for ( node =
prev; node; node = node->
prev )
439 if ( strcmp( node->
Value(), _value ) == 0 )
456 attributeSet.Remove( node );
525 for( node =
this; node; node = node->
parent )
577 while( attributeSet.
First() )
580 attributeSet.
Remove( node );
590 return node->
Value();
600 return &attrib->ValueStr();
609 const char* result = 0;
612 result = attrib->
Value();
625 const std::string* result = 0;
628 result = &attrib->ValueStr();
641 const char* result = 0;
644 result = attrib->
Value();
657 const std::string* result = 0;
660 result = &attrib->ValueStr();
687 *value = (unsigned)ival;
813 for ( i=0; i<depth; i++ ) {
814 fprintf( cfile,
" " );
817 fprintf( cfile,
"<%s",
value.c_str() );
820 for ( attrib = attributeSet.
First(); attrib; attrib = attrib->
Next() )
822 fprintf( cfile,
" " );
823 attrib->Print( cfile, depth );
833 fprintf( cfile,
" />" );
837 fprintf( cfile,
">" );
839 fprintf( cfile,
"</%s>",
value.c_str() );
843 fprintf( cfile,
">" );
849 fprintf( cfile,
"\n" );
851 node->
Print( cfile, depth+1 );
853 fprintf( cfile,
"\n" );
854 for( i=0; i<depth; ++
i ) {
855 fprintf( cfile,
" " );
857 fprintf( cfile,
"</%s>",
value.c_str() );
870 for( attribute = attributeSet.
First();
872 attribute = attribute->
Next() )
890 if ( !node->Accept( visitor ) )
915 return childText->
Value();
925 useMicrosoftBOM =
false;
932 useMicrosoftBOM =
false;
933 value = documentName;
942 useMicrosoftBOM =
false;
943 value = documentName;
984 bool result =
LoadFile( file, encoding );
1009 fseek( file, 0, SEEK_END );
1010 length = ftell( file );
1011 fseek( file, 0, SEEK_SET );
1041 char* buf =
new char[ length+1 ];
1044 if ( fread( buf, length, 1, file ) != 1 ) {
1061 const char* p = buf;
1063 const char CR = 0x0d;
1064 const char LF = 0x0a;
1068 assert( p < (buf+length) );
1069 assert( q <= (buf+length) );
1083 assert( q <= (buf+length) );
1086 Parse( buf, 0, encoding );
1109 if ( useMicrosoftBOM )
1115 fputc( TIXML_UTF_LEAD_0, fp );
1116 fputc( TIXML_UTF_LEAD_1, fp );
1117 fputc( TIXML_UTF_LEAD_2, fp );
1120 return (ferror(fp) == 0);
1128 target->error = error;
1129 target->errorId = errorId;
1130 target->errorDesc = errorDesc;
1131 target->tabsize = tabsize;
1132 target->errorLocation = errorLocation;
1133 target->useMicrosoftBOM = useMicrosoftBOM;
1159 node->Print( cfile, depth );
1160 fprintf( cfile,
"\n" );
1171 if ( !node->Accept( visitor ) )
1226 if (
value.find (
'\"') == TIXML_STRING::npos) {
1228 fprintf (cfile,
"%s=\"%s\"", n.c_str(), v.c_str() );
1231 (*str) += n; (*str) +=
"=\""; (*str) += v; (*str) +=
"\"";
1236 fprintf (cfile,
"%s='%s'", n.c_str(), v.c_str() );
1239 (*str) += n; (*str) +=
"='"; (*str) += v; (*str) +=
"'";
1262 #if defined(TIXML_SNPRINTF) 1265 sprintf (buf,
"%d", _value);
1273 #if defined(TIXML_SNPRINTF) 1276 sprintf (buf,
"%g", _value);
1283 return atoi (
value.c_str ());
1288 return atof (
value.c_str ());
1309 for (
int i=0;
i<depth;
i++ )
1311 fprintf( cfile,
" " );
1313 fprintf( cfile,
"<!--%s-->",
value.c_str() );
1325 return visitor->
Visit( *
this );
1347 fprintf( cfile,
"\n" );
1348 for ( i=0; i<depth; i++ ) {
1349 fprintf( cfile,
" " );
1351 fprintf( cfile,
"<![CDATA[%s]]>\n",
value.c_str() );
1357 fprintf( cfile,
"%s", buffer.c_str() );
1365 target->cdata = cdata;
1371 return visitor->
Visit( *
this );
1389 const char * _encoding,
1390 const char * _standalone )
1394 encoding = _encoding;
1395 standalone = _standalone;
1399 #ifdef TIXML_USE_STL 1401 const std::string& _encoding,
1402 const std::string& _standalone )
1406 encoding = _encoding;
1407 standalone = _standalone;
1429 if ( cfile ) fprintf( cfile,
"<?xml " );
1430 if ( str ) (*str) +=
"<?xml ";
1432 if ( !version.empty() ) {
1433 if ( cfile ) fprintf (cfile,
"version=\"%s\" ", version.c_str ());
1434 if ( str ) { (*str) +=
"version=\""; (*str) += version; (*str) +=
"\" "; }
1436 if ( !encoding.empty() ) {
1437 if ( cfile ) fprintf (cfile,
"encoding=\"%s\" ", encoding.c_str ());
1438 if ( str ) { (*str) +=
"encoding=\""; (*str) += encoding; (*str) +=
"\" "; }
1440 if ( !standalone.empty() ) {
1441 if ( cfile ) fprintf (cfile,
"standalone=\"%s\" ", standalone.c_str ());
1442 if ( str ) { (*str) +=
"standalone=\""; (*str) += standalone; (*str) +=
"\" "; }
1444 if ( cfile ) fprintf( cfile,
"?>" );
1445 if ( str ) (*str) +=
"?>";
1453 target->version = version;
1454 target->encoding = encoding;
1455 target->standalone = standalone;
1461 return visitor->
Visit( *
this );
1479 for (
int i=0;
i<depth;
i++ )
1480 fprintf( cfile,
" " );
1481 fprintf( cfile,
"<%s>",
value.c_str() );
1493 return visitor->
Visit( *
this );
1511 sentinel.next = &sentinel;
1512 sentinel.prev = &sentinel;
1518 assert( sentinel.next == &sentinel );
1519 assert( sentinel.prev == &sentinel );
1525 #ifdef TIXML_USE_STL 1528 assert( !Find( addMe->
Name() ) );
1531 addMe->next = &sentinel;
1532 addMe->prev = sentinel.prev;
1534 sentinel.prev->next = addMe;
1535 sentinel.prev = addMe;
1542 for( node = sentinel.next; node != &sentinel; node = node->next )
1544 if ( node == removeMe )
1546 node->prev->next = node->next;
1547 node->next->prev = node->prev;
1557 #ifdef TIXML_USE_STL 1560 for(
TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next )
1562 if ( node->name == name )
1583 for(
TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next )
1585 if ( strcmp( node->name.c_str(), name ) == 0 )
1604 #ifdef TIXML_USE_STL 1605 std::istream& operator>> (std::istream & in,
TiXmlNode & base)
1608 tag.reserve( 8 * 1000 );
1609 base.StreamIn( &in, &tag );
1617 #ifdef TIXML_USE_STL 1623 out << printer.Str();
1634 out.append( printer.Str() );
1779 buffer += element.
Value();
1781 for(
const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->
Next() )
1784 attrib->Print( 0, 0, &buffer );
1799 simpleTextPrint =
true;
1821 if ( simpleTextPrint )
1823 simpleTextPrint =
false;
1830 buffer += element.
Value();
1843 buffer +=
"<![CDATA[";
1844 buffer += text.
Value();
1848 else if ( simpleTextPrint )
1869 declaration.
Print( 0, 0, &buffer );
1879 buffer += comment.
Value();
1890 buffer += unknown.
Value();
const TiXmlAttribute * First() const
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
virtual bool Accept(TiXmlVisitor *visitor) const
const TIXML_STRING & ValueTStr() const
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
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.
int QueryBoolAttribute(const char *name, bool *_value) const
TiXmlHandle FirstChild() const
Return a handle to the first child node.
void CopyTo(TiXmlUnknown *target) const
TiXmlElement & operator=(const TiXmlElement &base)
void SetDoubleAttribute(const char *name, double value)
TiXmlAttribute * FindOrCreate(const char *_name)
virtual void Print(FILE *cfile, int depth) const
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
const unsigned char TIXML_UTF_LEAD_2
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
void SetName(const char *_name)
Set the name of this attribute.
TiXmlDocument()
Create an empty document, that has no name.
const char * Value() const
Return the value of this attribute.
int QueryIntValue(int *_value) const
virtual void Print(FILE *cfile, int depth) const
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
void SetValue(const char *_value)
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
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
const TiXmlEncoding TIXML_DEFAULT_ENCODING
TiXmlHandle ChildElement(const char *value, int index) const
virtual bool Accept(TiXmlVisitor *content) const
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.
const unsigned char TIXML_UTF_LEAD_1
TiXmlAttribute * Find(const char *_name) const
void RemoveAttribute(const char *name)
virtual TiXmlNode * Clone() const
void SetAttribute(const char *name, const char *_value)
virtual void Print(FILE *cfile, int depth) const
virtual void Print(FILE *cfile, int depth) const
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
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().
FILE * TiXmlFOpen(const char *filename, const char *mode)
TiXmlElement(const char *in_value)
Construct an element.
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
const unsigned char TIXML_UTF_LEAD_0
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Log & operator<<(Log &log, T data)
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
void Add(TiXmlAttribute *attribute)
const TiXmlDocument * GetDocument() const
bool CDATA() const
Queries whether this represents text using a CDATA section.
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
const TiXmlElement * NextSiblingElement() const
TiXmlDeclaration & operator=(const TiXmlDeclaration ©)
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
int QueryIntAttribute(const char *name, int *_value) const
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
virtual bool Accept(TiXmlVisitor *content) const
TiXmlNode(NodeType _type)
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
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.
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().
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
const char * Value() const
TiXmlDocument & operator=(const TiXmlDocument ©)
void CopyTo(TiXmlText *target) const
void CopyTo(TiXmlElement *target) const
virtual bool Accept(TiXmlVisitor *visitor) const
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
const char * GetText() const
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.
int QueryUnsignedAttribute(const char *name, unsigned *_value) const
QueryUnsignedAttribute examines the attribute - see QueryIntAttribute().
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
TiXmlDeclaration()
Construct an empty declaration.
const char * Attribute(const char *name) const
virtual void Print(FILE *cfile, int depth) const =0
virtual bool Accept(TiXmlVisitor *content) const
virtual TiXmlNode * Clone() const =0
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
void CopyTo(TiXmlDeclaration *target) const
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.