Go to the documentation of this file.
34 FILE*
TiXmlFOpen(
const char* filename,
const char* mode );
36 bool TiXmlBase::condenseWhiteSpace =
true;
39 FILE*
TiXmlFOpen(
const char* filename,
const char* mode )
41 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
43 errno_t err = fopen_s( &fp, filename, mode );
48 return fopen( filename, mode );
56 while( i<(
int)str.length() )
58 unsigned char c = (
unsigned char) str[i];
61 && i < ( (
int)str.length() - 2 )
75 while ( i<(
int)str.length()-1 )
77 outString->append( str.c_str() + i, 1 );
85 outString->append( entity[0].str, entity[0].strLength );
90 outString->append( entity[1].str, entity[1].strLength );
95 outString->append( entity[2].str, entity[2].strLength );
100 outString->append( entity[3].str, entity[3].strLength );
103 else if ( c ==
'\'' )
105 outString->append( entity[4].str, entity[4].strLength );
114 #if defined(TIXML_SNPRINTF)
115 TIXML_SNPRINTF( buf,
sizeof(buf),
"&#x%02X;", (
unsigned) ( c & 0xff ) );
117 sprintf( buf,
"&#x%02X;", (
unsigned) ( c & 0xff ) );
122 outString->append( buf, (
int)strlen( buf ) );
129 *outString += (char) c;
232 if ( !beforeThis || beforeThis->
parent !=
this ) {
247 node->
next = beforeThis;
249 if ( beforeThis->
prev )
258 beforeThis->
prev = node;
265 if ( !afterThis || afterThis->
parent !=
this ) {
280 node->
prev = afterThis;
282 if ( afterThis->
next )
291 afterThis->
next = node;
301 if ( replaceThis->
parent !=
this )
304 if ( withThis.ToDocument() ) {
319 if ( replaceThis->
next )
324 if ( replaceThis->
prev )
341 if ( removeThis->
parent !=
this )
347 if ( removeThis->
next )
352 if ( removeThis->
prev )
366 if ( strcmp( node->
Value(), _value ) == 0 )
378 if ( strcmp( node->
Value(), _value ) == 0 )
393 assert( previous->
parent ==
this );
407 assert( previous->
parent ==
this );
416 for ( node =
next; node; node = node->
next )
418 if ( strcmp( node->
Value(), _value ) == 0 )
428 for ( node =
prev; node; node = node->
prev )
430 if ( strcmp( node->
Value(), _value ) == 0 )
441 attributeSet.
Remove( node );
454 if ( node->ToElement() )
455 return node->ToElement();
469 if ( node->ToElement() )
470 return node->ToElement();
484 if ( node->ToElement() )
485 return node->ToElement();
499 if ( node->ToElement() )
500 return node->ToElement();
510 for( node =
this; node; node = node->
parent )
512 if ( node->ToDocument() )
513 return node->ToDocument();
550 while( attributeSet.
First() )
553 attributeSet.
Remove( node );
562 return attrib->ValueStr();
563 return std::string();
572 result = attrib->ValueStr();
583 std::string result = 0;
586 result = attrib->ValueStr();
607 for ( i=0; i<depth; i++ ) {
608 fprintf( cfile,
" " );
611 fprintf( cfile,
"<%s",
value.c_str() );
614 for ( attrib = attributeSet.
First(); attrib; attrib = attrib->
Next() )
616 fprintf( cfile,
" " );
617 attrib->
Print( cfile, depth );
627 fprintf( cfile,
" />" );
631 fprintf( cfile,
">" );
633 fprintf( cfile,
"</%s>",
value.c_str() );
637 fprintf( cfile,
">" );
641 if ( !node->ToText() )
643 fprintf( cfile,
"\n" );
645 node->
Print( cfile, depth+1 );
647 fprintf( cfile,
"\n" );
648 for( i=0; i<depth; ++i ) {
649 fprintf( cfile,
" " );
651 fprintf( cfile,
"</%s>",
value.c_str() );
664 for( attribute = attributeSet.
First();
666 attribute = attribute->
Next() )
668 target->
SetAttribute( attribute->Name(), attribute->Value() );
684 if ( !node->Accept( visitor ) )
707 const TiXmlText* childText = child->ToText();
709 return childText->
Value();
719 useMicrosoftBOM =
false;
726 useMicrosoftBOM =
false;
727 value = documentName;
736 useMicrosoftBOM =
false;
737 value = documentName;
778 bool result =
LoadFile( file, encoding );
803 fseek( file, 0, SEEK_END );
804 length = ftell( file );
805 fseek( file, 0, SEEK_SET );
835 char* buf =
new char[ length+1 ];
838 if ( fread( buf, length, 1, file ) != 1 ) {
857 const char CR = 0x0d;
858 const char LF = 0x0a;
862 assert( p < (buf+length) );
863 assert( q <= (buf+length) );
877 assert( q <= (buf+length) );
880 Parse( buf, 0, encoding );
903 if ( useMicrosoftBOM )
914 return (ferror(fp) == 0);
922 target->error = error;
923 target->errorId = errorId;
924 target->errorDesc = errorDesc;
925 target->tabsize = tabsize;
926 target->errorLocation = errorLocation;
927 target->useMicrosoftBOM = useMicrosoftBOM;
953 node->
Print( cfile, depth );
954 fprintf( cfile,
"\n" );
965 if ( !node->
Accept( visitor ) )
977 if ( next->value.empty() && next->name.empty() )
997 if ( prev->value.empty() && prev->name.empty() )
1020 if (value.find (
'\"') == TIXML_STRING::npos) {
1022 fprintf (cfile,
"%s=\"%s\"", n.c_str(), v.c_str() );
1025 (*str) += n; (*str) +=
"=\""; (*str) += v; (*str) +=
"\"";
1030 fprintf (cfile,
"%s='%s'", n.c_str(), v.c_str() );
1033 (*str) += n; (*str) +=
"='"; (*str) += v; (*str) +=
"'";
1056 #if defined(TIXML_SNPRINTF)
1059 sprintf (buf,
"%d", _value);
1067 #if defined(TIXML_SNPRINTF)
1070 sprintf (buf,
"%g", _value);
1077 return atoi (value.c_str ());
1082 return atof (value.c_str ());
1103 for (
int i=0; i<depth; i++ )
1105 fprintf( cfile,
" " );
1107 fprintf( cfile,
"<!--%s-->",
value.c_str() );
1119 return visitor->
Visit( *
this );
1141 fprintf( cfile,
"\n" );
1142 for ( i=0; i<depth; i++ ) {
1143 fprintf( cfile,
" " );
1145 fprintf( cfile,
"<![CDATA[%s]]>\n",
value.c_str() );
1151 fprintf( cfile,
"%s", buffer.c_str() );
1159 target->cdata = cdata;
1165 return visitor->
Visit( *
this );
1183 const char * _encoding,
1184 const char * _standalone )
1188 encoding = _encoding;
1189 standalone = _standalone;
1193 #ifdef TIXML_USE_STL
1195 const std::string& _encoding,
1196 const std::string& _standalone )
1200 encoding = _encoding;
1201 standalone = _standalone;
1223 if ( cfile ) fprintf( cfile,
"<?xml " );
1224 if ( str ) (*str) +=
"<?xml ";
1226 if ( !version.empty() ) {
1227 if ( cfile ) fprintf (cfile,
"version=\"%s\" ", version.c_str ());
1228 if ( str ) { (*str) +=
"version=\""; (*str) += version; (*str) +=
"\" "; }
1230 if ( !encoding.empty() ) {
1231 if ( cfile ) fprintf (cfile,
"encoding=\"%s\" ", encoding.c_str ());
1232 if ( str ) { (*str) +=
"encoding=\""; (*str) += encoding; (*str) +=
"\" "; }
1234 if ( !standalone.empty() ) {
1235 if ( cfile ) fprintf (cfile,
"standalone=\"%s\" ", standalone.c_str ());
1236 if ( str ) { (*str) +=
"standalone=\""; (*str) += standalone; (*str) +=
"\" "; }
1238 if ( cfile ) fprintf( cfile,
"?>" );
1239 if ( str ) (*str) +=
"?>";
1247 target->version = version;
1248 target->encoding = encoding;
1249 target->standalone = standalone;
1255 return visitor->
Visit( *
this );
1273 for (
int i=0; i<depth; i++ )
1274 fprintf( cfile,
" " );
1275 fprintf( cfile,
"<%s>",
value.c_str() );
1287 return visitor->
Visit( *
this );
1305 sentinel.next = &sentinel;
1306 sentinel.prev = &sentinel;
1312 assert( sentinel.next == &sentinel );
1313 assert( sentinel.prev == &sentinel );
1319 #ifdef TIXML_USE_STL
1322 assert( !
Find( addMe->Name() ) );
1325 addMe->next = &sentinel;
1326 addMe->prev = sentinel.prev;
1328 sentinel.prev->next = addMe;
1329 sentinel.prev = addMe;
1336 for( node = sentinel.next; node != &sentinel; node = node->next )
1338 if ( node == removeMe )
1340 node->prev->next = node->next;
1341 node->next->prev = node->prev;
1351 #ifdef TIXML_USE_STL
1356 if ( node->name == name )
1379 if ( strcmp( node->name.c_str(), name ) == 0 )
1398 #ifdef TIXML_USE_STL
1402 tag.reserve( 8 * 1000 );
1405 base.
Parse( tag.c_str(), 0, TIXML_DEFAULT_ENCODING );
1411 #ifdef TIXML_USE_STL
1417 out << printer.
Str();
1428 out.append( printer.
Str() );
1573 buffer += element.
Value();
1575 for(
const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->
Next() )
1578 attrib->Print( 0, 0, &buffer );
1591 && element.
FirstChild()->ToText()->CDATA() ==
false )
1593 simpleTextPrint =
true;
1615 if ( simpleTextPrint )
1617 simpleTextPrint =
false;
1624 buffer += element.
Value();
1637 buffer +=
"<![CDATA[";
1638 buffer += text.
Value();
1642 else if ( simpleTextPrint )
1663 declaration.
Print( 0, 0, &buffer );
1673 buffer += comment.
Value();
1684 buffer += unknown.
Value();
TiXmlDeclaration()
Construct an empty declaration.
TiXmlAttribute * FindOrCreate(const char *_name)
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
const TiXmlElement * NextSiblingElement() const
virtual bool Accept(TiXmlVisitor *visitor) const
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
TiXmlDeclaration & operator=(const TiXmlDeclaration ©)
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
const unsigned char TIXML_UTF_LEAD_2
virtual bool Accept(TiXmlVisitor *content) const
TiXmlAttribute * Find(const char *_name) const
const unsigned char TIXML_UTF_LEAD_1
const char * GetText() const
friend class TiXmlElement
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
int QueryIntValue(int *_value) const
const TiXmlNode * LastChild() const
virtual void Print(FILE *cfile, int depth) const
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
void CopyTo(TiXmlUnknown *target) const
const TIXML_STRING & ValueTStr() const
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
virtual TiXmlNode * Clone() const
TiXmlHandle ChildElement(const char *value, int index) const
TiXmlHandle FirstChild() const
Return a handle to the first child node.
virtual void Print(FILE *cfile, int depth) const =0
void Add(TiXmlAttribute *attribute)
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
void SetIntValue(int _value)
Set the value from an integer.
const TiXmlDocument * GetDocument() const
void SetName(const std::string &_name)
STL std::string form.
TiXmlText(const char *initValue)
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
TiXmlDocument & operator=(const TiXmlDocument ©)
double DoubleValue() const
Return the value of this attribute, converted to a double.
void SetDoubleValue(double _value)
Set the value from a double.
void CopyTo(TiXmlText *target) const
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
std::istream & operator>>(std::istream &in, TiXmlNode &base)
std::string Attribute(const std::string &name) const
@ TIXML_ERROR_DOCUMENT_TOP_ONLY
virtual bool Accept(TiXmlVisitor *content) const
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
void RemoveAttribute(const std::string &name)
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
void CopyTo(TiXmlElement *target) const
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
int IntValue() const
Return the value of this attribute, converted to an integer.
void Clear()
Delete all the children of this node. Does not affect 'this'.
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
virtual void Print(FILE *cfile, int depth) const
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
const char * Value() const
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
virtual bool Accept(TiXmlVisitor *visitor) const =0
void SetAttribute(const std::string &name, const std::string &_value)
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
void * userData
Field containing a generic user pointer.
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
TiXmlHandle Child(const char *value, int index) const
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
void CopyTo(TiXmlDeclaration *target) const
virtual bool Accept(TiXmlVisitor *content) const
virtual bool Accept(TiXmlVisitor *visitor) const
void CopyTo(TiXmlNode *target) const
std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)
virtual TiXmlNode * Clone() const =0
bool CDATA() const
Queries whether this represents text using a CDATA section.
const std::string & Str()
Return the result.
TiXmlElement & operator=(const TiXmlElement &base)
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
@ TIXML_ERROR_DOCUMENT_EMPTY
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
FILE * TiXmlFOpen(const char *filename, const char *mode)
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
virtual void Print(FILE *cfile, int depth) const
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
void SetValue(const char *_value)
void SetValue(const std::string &_value)
STL std::string form.
const TiXmlAttribute * First() const
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
const unsigned char TIXML_UTF_LEAD_0
virtual void Print(FILE *cfile, int depth) const
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
TiXmlDocument()
Create an empty document, that has no name.
@ TIXML_ERROR_OPENING_FILE
void Remove(TiXmlAttribute *attribute)
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0