33 FILE*
TiXmlFOpen(
const char* filename,
const char* mode );
35 bool TiXmlBase::condenseWhiteSpace =
true;
38 FILE*
TiXmlFOpen(
const char* filename,
const char* mode )
40 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
42 errno_t err = fopen_s( &fp, filename, mode );
47 return fopen( filename, mode );
55 while( i<(
int)str.length() )
57 unsigned char c = (
unsigned char) str[i];
60 && i < ( (
int)str.length() - 2 )
74 while ( i<(
int)str.length()-1 )
76 outString->append( str.c_str() + i, 1 );
84 outString->append( entity[0].str, entity[0].strLength );
89 outString->append( entity[1].str, entity[1].strLength );
94 outString->append( entity[2].str, entity[2].strLength );
99 outString->append( entity[3].str, entity[3].strLength );
102 else if ( c ==
'\'' )
104 outString->append( entity[4].str, entity[4].strLength );
113 #if defined(TIXML_SNPRINTF)
114 TIXML_SNPRINTF( buf,
sizeof(buf),
"&#x%02X;", (
unsigned) ( c & 0xff ) );
116 sprintf( buf,
"&#x%02X;", (
unsigned) ( c & 0xff ) );
121 outString->append( buf, (
int)strlen( buf ) );
128 *outString += (char) c;
231 if ( !beforeThis || beforeThis->
parent !=
this ) {
246 node->
next = beforeThis;
248 if ( beforeThis->
prev )
257 beforeThis->
prev = node;
264 if ( !afterThis || afterThis->
parent !=
this ) {
279 node->
prev = afterThis;
281 if ( afterThis->
next )
290 afterThis->
next = node;
300 if ( replaceThis->
parent !=
this )
318 if ( replaceThis->
next )
323 if ( replaceThis->
prev )
340 if ( removeThis->
parent !=
this )
346 if ( removeThis->
next )
351 if ( removeThis->
prev )
365 if ( strcmp( node->
Value(), _value ) == 0 )
377 if ( strcmp( node->
Value(), _value ) == 0 )
392 assert( previous->
parent ==
this );
406 assert( previous->
parent ==
this );
415 for ( node =
next; node; node = node->
next )
417 if ( strcmp( node->
Value(), _value ) == 0 )
427 for ( node =
prev; node; node = node->
prev )
429 if ( strcmp( node->
Value(), _value ) == 0 )
446 attributeSet.
Remove( node );
515 for( node =
this; node; node = node->
parent )
567 while( attributeSet.
First() )
570 attributeSet.
Remove( node );
580 return node->
Value();
590 return &attrib->ValueStr();
599 const char* result = 0;
602 result = attrib->
Value();
615 const std::string* result = 0;
618 result = &attrib->ValueStr();
631 const char* result = 0;
634 result = attrib->
Value();
647 const std::string* result = 0;
650 result = &attrib->ValueStr();
677 *value = (unsigned)ival;
803 for ( i=0; i<depth; i++ ) {
804 fprintf( cfile,
" " );
807 fprintf( cfile,
"<%s",
value.c_str() );
810 for ( attrib = attributeSet.
First(); attrib; attrib = attrib->
Next() )
812 fprintf( cfile,
" " );
813 attrib->Print( cfile, depth );
823 fprintf( cfile,
" />" );
827 fprintf( cfile,
">" );
829 fprintf( cfile,
"</%s>",
value.c_str() );
833 fprintf( cfile,
">" );
839 fprintf( cfile,
"\n" );
841 node->
Print( cfile, depth+1 );
843 fprintf( cfile,
"\n" );
844 for( i=0; i<depth; ++i ) {
845 fprintf( cfile,
" " );
847 fprintf( cfile,
"</%s>",
value.c_str() );
860 for( attribute = attributeSet.
First();
862 attribute = attribute->
Next() )
880 if ( !node->Accept( visitor ) )
905 return childText->
Value();
915 useMicrosoftBOM =
false;
922 useMicrosoftBOM =
false;
923 value = documentName;
932 useMicrosoftBOM =
false;
933 value = documentName;
974 bool result =
LoadFile( file, encoding );
999 fseek( file, 0, SEEK_END );
1000 length = ftell( file );
1001 fseek( file, 0, SEEK_SET );
1031 char* buf =
new char[ length+1 ];
1034 if ( fread( buf, length, 1, file ) != 1 ) {
1051 const char* p = buf;
1053 const char CR = 0x0d;
1054 const char LF = 0x0a;
1058 assert( p < (buf+length) );
1059 assert( q <= (buf+length) );
1073 assert( q <= (buf+length) );
1076 Parse( buf, 0, encoding );
1099 if ( useMicrosoftBOM )
1105 fputc( TIXML_UTF_LEAD_0, fp );
1106 fputc( TIXML_UTF_LEAD_1, fp );
1107 fputc( TIXML_UTF_LEAD_2, fp );
1110 return (ferror(fp) == 0);
1118 target->error = error;
1119 target->errorId = errorId;
1120 target->errorDesc = errorDesc;
1121 target->tabsize = tabsize;
1122 target->errorLocation = errorLocation;
1123 target->useMicrosoftBOM = useMicrosoftBOM;
1149 node->
Print( cfile, depth );
1150 fprintf( cfile,
"\n" );
1161 if ( !node->
Accept( visitor ) )
1173 if ( next->value.empty() && next->name.empty() )
1193 if ( prev->value.empty() && prev->name.empty() )
1216 if (value.find (
'\"') == TIXML_STRING::npos) {
1218 fprintf (cfile,
"%s=\"%s\"", n.c_str(), v.c_str() );
1221 (*str) += n; (*str) +=
"=\""; (*str) += v; (*str) +=
"\"";
1226 fprintf (cfile,
"%s='%s'", n.c_str(), v.c_str() );
1229 (*str) += n; (*str) +=
"='"; (*str) += v; (*str) +=
"'";
1252 #if defined(TIXML_SNPRINTF)
1255 sprintf (buf,
"%d", _value);
1263 #if defined(TIXML_SNPRINTF)
1266 sprintf (buf,
"%g", _value);
1273 return atoi (value.c_str ());
1278 return atof (value.c_str ());
1299 for (
int i=0; i<depth; i++ )
1301 fprintf( cfile,
" " );
1303 fprintf( cfile,
"<!--%s-->",
value.c_str() );
1315 return visitor->
Visit( *
this );
1337 fprintf( cfile,
"\n" );
1338 for ( i=0; i<depth; i++ ) {
1339 fprintf( cfile,
" " );
1341 fprintf( cfile,
"<![CDATA[%s]]>\n",
value.c_str() );
1347 fprintf( cfile,
"%s", buffer.c_str() );
1355 target->cdata = cdata;
1361 return visitor->
Visit( *
this );
1379 const char * _encoding,
1380 const char * _standalone )
1384 encoding = _encoding;
1385 standalone = _standalone;
1389 #ifdef TIXML_USE_STL
1391 const std::string& _encoding,
1392 const std::string& _standalone )
1396 encoding = _encoding;
1397 standalone = _standalone;
1419 if ( cfile ) fprintf( cfile,
"<?xml " );
1420 if ( str ) (*str) +=
"<?xml ";
1422 if ( !version.empty() ) {
1423 if ( cfile ) fprintf (cfile,
"version=\"%s\" ", version.c_str ());
1424 if ( str ) { (*str) +=
"version=\""; (*str) += version; (*str) +=
"\" "; }
1426 if ( !encoding.empty() ) {
1427 if ( cfile ) fprintf (cfile,
"encoding=\"%s\" ", encoding.c_str ());
1428 if ( str ) { (*str) +=
"encoding=\""; (*str) += encoding; (*str) +=
"\" "; }
1430 if ( !standalone.empty() ) {
1431 if ( cfile ) fprintf (cfile,
"standalone=\"%s\" ", standalone.c_str ());
1432 if ( str ) { (*str) +=
"standalone=\""; (*str) += standalone; (*str) +=
"\" "; }
1434 if ( cfile ) fprintf( cfile,
"?>" );
1435 if ( str ) (*str) +=
"?>";
1443 target->version = version;
1444 target->encoding = encoding;
1445 target->standalone = standalone;
1451 return visitor->
Visit( *
this );
1469 for (
int i=0; i<depth; i++ )
1470 fprintf( cfile,
" " );
1471 fprintf( cfile,
"<%s>",
value.c_str() );
1483 return visitor->
Visit( *
this );
1501 sentinel.next = &sentinel;
1502 sentinel.prev = &sentinel;
1508 assert( sentinel.next == &sentinel );
1509 assert( sentinel.prev == &sentinel );
1515 #ifdef TIXML_USE_STL
1521 addMe->next = &sentinel;
1522 addMe->prev = sentinel.prev;
1524 sentinel.prev->next = addMe;
1525 sentinel.prev = addMe;
1532 for( node = sentinel.next; node != &sentinel; node = node->next )
1534 if ( node == removeMe )
1536 node->prev->next = node->next;
1537 node->next->prev = node->prev;
1547 #ifdef TIXML_USE_STL
1552 if ( node->name == name )
1575 if ( strcmp( node->name.c_str(), name ) == 0 )
1594 #ifdef TIXML_USE_STL
1598 tag.reserve( 8 * 1000 );
1599 base.StreamIn( &in, &tag );
1607 #ifdef TIXML_USE_STL
1613 out << printer.Str();
1624 out.append( printer.Str() );
1769 buffer += element.
Value();
1771 for(
const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->
Next() )
1774 attrib->
Print( 0, 0, &buffer );
1789 simpleTextPrint =
true;
1811 if ( simpleTextPrint )
1813 simpleTextPrint =
false;
1820 buffer += element.
Value();
1833 buffer +=
"<![CDATA[";
1834 buffer += text.
Value();
1838 else if ( simpleTextPrint )
1859 declaration.
Print( 0, 0, &buffer );
1869 buffer += comment.
Value();
1880 buffer += unknown.
Value();
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
void SetDoubleAttribute(const char *name, double value)
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
TiXmlAttribute * Find(const char *_name) const
void CopyTo(TiXmlElement *target) const
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
const TiXmlNode * LastChild() const
virtual TiXmlNode * Clone() const =0
TiXmlElement & operator=(const TiXmlElement &base)
const TiXmlAttribute * First() const
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
void SetDoubleValue(double _value)
Set the value from a double.
void RemoveAttribute(const char *name)
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
const unsigned char TIXML_UTF_LEAD_2
virtual bool Accept(TiXmlVisitor *visitor) const
QDataStream & operator<<(QDataStream &ds, const CObject &obj)
void SetIntValue(int _value)
Set the value from an integer.
void CopyTo(TiXmlDeclaration *target) const
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
TiXmlDocument()
Create an empty document, that has no name.
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
const char * Value() const
TiXmlAttribute * FindOrCreate(const char *_name)
int IntValue() const
Return the value of this attribute, converted to an integer.
int QueryIntAttribute(const char *name, int *_value) const
const char * Name() const
Return the name of this attribute.
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
void CopyTo(TiXmlText *target) const
void Add(TiXmlAttribute *attribute)
TiXmlDeclaration & operator=(const TiXmlDeclaration ©)
QDataStream & operator>>(QDataStream &ds, CObject &obj)
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
virtual bool Accept(TiXmlVisitor *visitor) const
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
TiXmlText(const char *initValue)
int QueryIntValue(int *_value) const
void SetName(const char *_name)
Set the name of this attribute.
const TiXmlEncoding TIXML_DEFAULT_ENCODING
int QueryBoolAttribute(const char *name, bool *_value) const
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
TiXmlNode(NodeType _type)
void Clear()
Delete all the children of this node. Does not affect 'this'.
virtual bool Accept(TiXmlVisitor *content) const
const unsigned char TIXML_UTF_LEAD_1
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
const TiXmlElement * NextSiblingElement() const
TiXmlElement(const char *in_value)
Construct an element.
TiXmlDeclaration()
Construct an empty declaration.
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
FILE * TiXmlFOpen(const char *filename, const char *mode)
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
virtual TiXmlNode * Clone() const
virtual bool Accept(TiXmlVisitor *visitor) const =0
const unsigned char TIXML_UTF_LEAD_0
void * userData
Field containing a generic user pointer.
TiXmlDocument & operator=(const TiXmlDocument ©)
const char * Attribute(const char *name) const
void SetValue(const char *_value)
Set the value.
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
virtual void Print(FILE *cfile, int depth) const
virtual bool Accept(TiXmlVisitor *content) const
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
const TIXML_STRING & ValueTStr() const
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
void CopyTo(TiXmlUnknown *target) const
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
void SetAttribute(const char *name, const char *_value)
void SetValue(const char *_value)
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
const char * GetText() const
virtual void Print(FILE *cfile, int depth) const
int QueryUnsignedAttribute(const char *name, unsigned *_value) const
QueryUnsignedAttribute examines the attribute - see QueryIntAttribute().
virtual void Print(FILE *cfile, int depth) const =0
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
virtual bool Accept(TiXmlVisitor *content) const
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
TiXmlHandle FirstChild() const
Return a handle to the first child node.
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
TiXmlHandle Child(const char *value, int index) const
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
void Remove(TiXmlAttribute *attribute)
const char * Value() const
Return the value of this attribute.
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
const TiXmlDocument * GetDocument() const
virtual void Print(FILE *cfile, int depth) const
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
virtual void Print(FILE *cfile, int depth) const
double DoubleValue() const
Return the value of this attribute, converted to a double.
bool CDATA() const
Queries whether this represents text using a CDATA section.
TiXmlHandle ChildElement(const char *value, int index) const
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
void CopyTo(TiXmlNode *target) const
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.