37 FILE*
TiXmlFOpen(
const char* filename,
const char* mode) {
38 #if defined(_MSC_VER) && (_MSC_VER >= 1400) 40 errno_t err = fopen_s(&fp, filename, mode);
42 if (!err && fp)
return fp;
46 return fopen(filename, mode);
53 while (i < (
int)str.length()) {
54 unsigned char c = (
unsigned char)str[i];
56 if (c ==
'&' && i < ((
int)str.length() - 2) && str[i + 1] ==
'#' &&
68 while (i < (
int)str.length() - 1) {
69 outString->append(str.c_str() + i, 1);
72 if (str[i] ==
';')
break;
74 }
else if (c ==
'&') {
77 }
else if (c ==
'<') {
80 }
else if (c ==
'>') {
83 }
else if (c ==
'\"') {
86 }
else if (c ==
'\'') {
94 #if defined(TIXML_SNPRINTF) 95 TIXML_SNPRINTF(buf,
sizeof(buf),
"&#x%02X;", (
unsigned)(c & 0xff));
97 sprintf(buf,
"&#x%02X;", (
unsigned)(c & 0xff));
102 outString->append(buf, (
int)strlen(buf));
107 *outString += (char)c;
199 if (!beforeThis || beforeThis->
parent !=
this) {
217 node->
next = beforeThis;
220 if (beforeThis->
prev) {
227 beforeThis->
prev = node;
233 if (!afterThis || afterThis->
parent !=
this) {
251 node->
prev = afterThis;
254 if (afterThis->
next) {
261 afterThis->
next = node;
267 if (replaceThis->
parent !=
this)
return 0;
276 if (replaceThis->
next)
281 if (replaceThis->
prev)
292 if (removeThis->
parent !=
this) {
297 if (removeThis->
next)
302 if (removeThis->
prev)
315 if (strcmp(node->
Value(), _value) == 0)
return node;
325 if (strcmp(node->
Value(), _value) == 0)
return node;
335 assert(previous->
parent ==
this);
345 assert(previous->
parent ==
this);
353 for (node =
next; node; node = node->
next) {
354 if (strcmp(node->
Value(), _value) == 0)
return node;
363 for (node =
prev; node; node = node->
prev) {
364 if (strcmp(node->
Value(), _value) == 0)
return node;
379 attributeSet.Remove(node);
427 for (node =
this; node; node = node->
parent) {
474 if (node)
return node->
Value();
509 *i = atoi(s->c_str());
540 *d = atof(s->c_str());
578 double* dval)
const {
589 #if defined(TIXML_SNPRINTF) 590 TIXML_SNPRINTF(buf,
sizeof(buf),
"%d", val);
592 sprintf(buf,
"%d", val);
599 std::ostringstream oss;
607 #if defined(TIXML_SNPRINTF) 608 TIXML_SNPRINTF(buf,
sizeof(buf),
"%f", val);
610 sprintf(buf,
"%f", val);
620 const char* _name = cname;
621 const char* _value = cvalue;
645 const std::string& _value) {
670 for (i = 0; i < depth; i++) {
674 fprintf(cfile,
"<%s",
value.c_str());
680 attrib->Print(cfile, depth);
690 fprintf(cfile,
" />");
694 fprintf(cfile,
"</%s>",
value.c_str());
700 fprintf(cfile,
"\n");
703 node->
Print(cfile, depth + 1);
706 fprintf(cfile,
"\n");
708 for (i = 0; i < depth; ++i) {
712 fprintf(cfile,
"</%s>",
value.c_str());
725 attribute = attribute->
Next()) {
739 if (!node->Accept(visitor))
break;
749 if (!clone)
return 0;
762 return childText->
Value();
780 value = documentName;
789 value = documentName;
837 bool result =
LoadFile(file, encoding);
858 fseek(file, 0, SEEK_END);
859 length = ftell(file);
860 fseek(file, 0, SEEK_SET);
873 data.reserve(length);
904 char* buf =
new char[length + 1];
907 if (fread(buf, length, 1, file) != 1) {
913 const char* lastPos = buf;
919 assert(p < (buf + length));
924 data.append(lastPos, (p - lastPos + 1));
927 assert(p <= (buf + length));
928 }
else if (*p == 0xd) {
931 if ((p - lastPos) > 0) {
932 data.append(lastPos, p - lastPos);
937 if (*(p + 1) == 0xa) {
941 assert(p <= (buf + length));
947 assert(p <= (buf + length));
956 data.append(lastPos, p - lastPos);
962 Parse(data.c_str(), 0, encoding);
989 fputc(TIXML_UTF_LEAD_0, fp);
990 fputc(TIXML_UTF_LEAD_1, fp);
991 fputc(TIXML_UTF_LEAD_2, fp);
995 return (ferror(fp) == 0);
1018 if (!clone)
return 0;
1028 node->Print(cfile, depth);
1029 fprintf(cfile,
"\n");
1036 if (!node->Accept(visitor))
break;
1087 if (
value.find(
'\"') == TIXML_STRING::npos) {
1089 fprintf(cfile,
"%s=\"%s\"", n.c_str(), v.c_str());
1100 fprintf(cfile,
"%s='%s'", n.c_str(), v.c_str());
1126 #if defined(TIXML_SNPRINTF) 1127 TIXML_SNPRINTF(buf,
sizeof(buf),
"%d", _value);
1129 sprintf(buf,
"%d", _value);
1136 #if defined(TIXML_SNPRINTF) 1137 TIXML_SNPRINTF(buf,
sizeof(buf),
"%g", _value);
1139 sprintf(buf,
"%lf", _value);
1161 for (
int i = 0; i < depth; i++) {
1162 fprintf(cfile,
" ");
1165 fprintf(cfile,
"<!--%s-->",
value.c_str());
1173 return visitor->
Visit(*
this);
1179 if (!clone)
return 0;
1190 fprintf(cfile,
"\n");
1192 for (i = 0; i < depth; i++) {
1193 fprintf(cfile,
" ");
1196 fprintf(cfile,
"<![CDATA[%s]]>\n",
value.c_str());
1200 fprintf(cfile,
"%s", buffer.c_str());
1206 target->
cdata = cdata;
1210 return visitor->
Visit(*
this);
1217 if (!clone)
return 0;
1224 const char* _encoding,
1225 const char* _standalone)
1232 #ifdef TIXML_USE_STL 1234 const std::string& _encoding,
1235 const std::string& _standalone)
1254 if (cfile) fprintf(cfile,
"<?xml ");
1256 if (str) (*str) +=
"<?xml ";
1259 if (cfile) fprintf(cfile,
"version=\"%s\" ",
version.c_str());
1262 (*str) +=
"version=\"";
1269 if (cfile) fprintf(cfile,
"encoding=\"%s\" ",
encoding.c_str());
1272 (*str) +=
"encoding=\"";
1279 if (cfile) fprintf(cfile,
"standalone=\"%s\" ",
standalone.c_str());
1282 (*str) +=
"standalone=\"";
1288 if (cfile) fprintf(cfile,
"?>");
1290 if (str) (*str) +=
"?>";
1302 return visitor->
Visit(*
this);
1308 if (!clone)
return 0;
1321 #ifdef TIXML_USE_STL 1323 const std::string& _href)
1344 if (cfile) fprintf(cfile,
"<?xml-stylesheet ");
1346 if (str) (*str) +=
"<?xml-stylesheet ";
1348 if (!
type.empty()) {
1349 if (cfile) fprintf(cfile,
"type=\"%s\" ",
type.c_str());
1352 (*str) +=
"type=\"";
1358 if (!
href.empty()) {
1359 if (cfile) fprintf(cfile,
"href=\"%s\" ",
href.c_str());
1362 (*str) +=
"href=\"";
1368 if (cfile) fprintf(cfile,
"?>");
1370 if (str) (*str) +=
"?>";
1381 return visitor->
Visit(*
this);
1387 if (!clone)
return 0;
1394 for (
int i = 0; i < depth; i++)
1395 fprintf(cfile,
" ");
1397 fprintf(cfile,
"<%s>",
value.c_str());
1405 return visitor->
Visit(*
this);
1411 if (!clone)
return 0;
1418 sentinel.next = &sentinel;
1419 sentinel.prev = &sentinel;
1423 assert(sentinel.next == &sentinel);
1424 assert(sentinel.prev == &sentinel);
1428 #ifdef TIXML_USE_STL 1432 assert(!Find(addMe->
Name()));
1435 addMe->
next = &sentinel;
1439 sentinel.
prev = addMe;
1445 for (node = sentinel.
next; node != &sentinel; node = node->
next) {
1446 if (node == removeMe) {
1458 #ifdef TIXML_USE_STL 1461 node = node->
next) {
1462 if (node->name == name)
return node;
1484 node = node->
next) {
1485 if (strcmp(node->name.c_str(), name) == 0)
return node;
1504 #ifdef TIXML_USE_STL 1507 tag.reserve(8 * 1000);
1515 #ifdef TIXML_USE_STL 1520 out << printer.
Str();
1529 out.append(printer.
Str());
1580 for (i = 0; child && i < count; child = child->
NextSibling(), ++i) {
1595 for (i = 0; child && i < count; child = child->
NextSibling(value), ++i) {
1625 for (i = 0; child && i < count;
1644 buffer += element.
Value();
1647 attrib = attrib->
Next()) {
1649 attrib->Print(0, 0, &buffer);
1661 simpleTextPrint =
true;
1678 if (simpleTextPrint) {
1679 simpleTextPrint =
false;
1685 buffer += element.
Value();
1696 buffer +=
"<![CDATA[";
1697 buffer += text.
Value();
1700 }
else if (simpleTextPrint) {
1717 declaration.
Print(0, 0, &buffer);
1725 buffer += comment.
Value();
1734 buffer += unknown.
Value();
1742 stylesheet.
Print(0, 0, &buffer);
int QueryIntValue(int *_value) const
QueryIntValue examines the value string.
An attribute is a name-value pair.
friend std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)
An output stream operator, for every class.
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks...
FILE * TiXmlFOpen(const char *filename, const char *mode)
const TiXmlNode * LastChild() 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 ...
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
const char * Name() const
Return the name of this attribute.
void Print() const
Write the document to standard out using formatted printing ("pretty print").
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
void CopyTo(TiXmlDocument *target) const
TiXmlHandle ChildElement(const char *value, int index) const
Return a handle to the "index" child element with the given name.
const char * GetText() const
Convenience function for easy access to the text inside an element.
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
bool Error() const
If an error occurs, Error will be set to true.
void operator=(const TiXmlDeclaration ©)
void operator=(const TiXmlDocument ©)
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
const unsigned char TIXML_UTF_LEAD_2
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
bool CDATA() const
Queries whether this represents text using a CDATA section.
TiXmlDocument()
Create an empty document, that has no name.
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
void CopyTo(TiXmlElement *target) const
void ClearError()
If you have handled the error, it can be reset with this call.
void CopyTo(TiXmlUnknown *target) const
friend std::istream & operator>>(std::istream &in, TiXmlNode &base)
An input stream operator, for every class.
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 TIXML_STRING & ValueTStr() const
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
void CopyTo(TiXmlDeclaration *target) const
static bool condenseWhiteSpace
const std::string & ValueStr() const
Return the value of this attribute.
NodeType
The types of XML nodes supported by TinyXml.
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
TiXmlHandle Child(const char *value, int index) const
Return a handle to the "index" child with the given name.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
void SetDoubleValue(double _value)
Set the value from a double.
void * userData
Field containing a generic user pointer.
A stylesheet reference looks like this:
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
In correct XML the declaration is the first entry in the file.
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
const char * Value() const
Return the value of this attribute.
TiXmlAttributeSet attributeSet
Any tag that tinyXml doesn't recognize is saved as an unknown.
int QueryIntAttribute(const char *name, int *_value) const
QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer...
const TiXmlEncoding TIXML_DEFAULT_ENCODING
int IntValue() const
Return the value of this attribute, converted to an integer.
TiXmlStylesheetReference()
Construct an empty declaration.
void CopyTo(TiXmlStylesheetReference *target) const
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
void CopyTo(TiXmlText *target) const
const unsigned char TIXML_UTF_LEAD_1
void RemoveAttribute(const char *name)
Deletes an attribute with the given name.
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 ...
double DoubleValue() const
Return the value of this attribute, converted to a double.
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
Always the top level node.
TiXmlHandle FirstChild() const
Return a handle to the first child node.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
TiXmlElement(const char *in_value)
Construct an element.
void operator=(const TiXmlStylesheetReference ©)
const unsigned char TIXML_UTF_LEAD_0
static Entity entity[NUM_ENTITY]
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
void CopyTo(TiXmlNode *target) const
void Add(TiXmlAttribute *attribute)
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
const TiXmlAttribute * Find(const char *_name) const
TiXmlBase is a base class for every class in TinyXml.
int Type() const
Query the type (as an enumerated value, above) of this node.
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 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)
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)
TiXmlNode(NodeType _type)
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
Expands entities in a string.
The parent class for everything in the Document Object Model.
const TiXmlAttribute * First() const
void SetIntValue(int _value)
Set the value from an integer.
Print to memory functionality.
virtual TiXmlNode * Clone() const
Creates a copy of this StylesheetReference and returns it.
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
virtual TiXmlNode * Clone() const
Create an exact duplicate of this node and return it.
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.
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
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 TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
const std::string & Str()
Return the result.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
TiXmlDeclaration()
Construct an empty declaration.
void SetStreamPrinting()
Switch over to "stream printing" which is the most dense formatting without linebreaks.
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 TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
The element is a container class.
TiXmlCursor errorLocation
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
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 bool Visit(const TiXmlDeclaration &)
Visit a declaration.