37FILE*
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 snprintf(buf, 32,
"&#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;
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 snprintf(buf, 64,
"%d", val);
599 std::ostringstream oss;
607#if defined(TIXML_SNPRINTF)
608 TIXML_SNPRINTF(buf,
sizeof(buf),
"%f", val);
610 snprintf(buf, 256,
"%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);
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;
1046 if (
next->value.empty() &&
next->name.empty())
return 0;
1065 if (
prev->value.empty() &&
prev->name.empty())
return 0;
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 snprintf(buf, 64,
"%d", _value);
1136#if defined(TIXML_SNPRINTF)
1137 TIXML_SNPRINTF(buf,
sizeof(buf),
"%g", _value);
1139 snprintf(buf, 256,
"%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());
1210 return visitor->
Visit(*
this);
1217 if (!clone)
return 0;
1224 const char* _encoding,
1225 const char* _standalone)
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;
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;
1446 if (node == removeMe) {
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;
1507 tag.reserve(8 * 1000);
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;
1647 attrib = attrib->
Next()) {
1649 attrib->Print(0, 0, &
buffer);
const TiXmlAttribute * Find(const char *_name) const
void Add(TiXmlAttribute *attribute)
void Remove(TiXmlAttribute *attribute)
An attribute is a name-value pair.
void SetDoubleValue(double _value)
Set the value from a double.
const char * Value() const
Return the value of this attribute.
void SetValue(const char *_value)
Set the 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 ...
int QueryIntValue(int *_value) const
QueryIntValue examines the value string.
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
void SetIntValue(int _value)
Set the value from an integer.
const char * Name() const
Return the name of this attribute.
double DoubleValue() const
Return the value of this attribute, converted to a double.
TiXmlAttribute()
Construct an empty attribute.
int IntValue() const
Return the value of this attribute, converted to an integer.
const std::string & ValueStr() const
Return the value of this attribute.
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
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 ...
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
Expands entities in a string.
static bool condenseWhiteSpace
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
@ TIXML_ERROR_DOCUMENT_TOP_ONLY
@ TIXML_ERROR_OUT_OF_MEMORY
@ TIXML_ERROR_DOCUMENT_EMPTY
@ TIXML_ERROR_OPENING_FILE
static Entity entity[NUM_ENTITY]
void * userData
Field containing a generic user pointer.
friend class TiXmlElement
In correct XML the declaration is the first entry in the file.
void operator=(const TiXmlDeclaration ©)
void CopyTo(TiXmlDeclaration *target) const
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
TiXmlDeclaration()
Construct an empty declaration.
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
Always the top level node.
bool Error() const
If an error occurs, Error will be set to true.
virtual TiXmlNode * Clone() const
Create an exact duplicate of this node and return it.
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given null terminated block of xml data.
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
TiXmlDocument()
Create an empty document, that has no name.
TiXmlCursor errorLocation
void Print() const
Write the document to standard out using formatted printing ("prettyprint").
void CopyTo(TiXmlDocument *target) const
void operator=(const TiXmlDocument ©)
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
void ClearError()
If you have handled the error, it can be reset with this call.
The element is a container class.
TiXmlElement(const char *in_value)
Construct an element.
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
void RemoveAttribute(const char *name)
Deletes an attribute with the given name.
TiXmlAttributeSet attributeSet
int QueryIntAttribute(const char *name, int *_value) const
QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer...
const char * Attribute(const char *name) const
Given an attribute name, Attribute() returns the value for the attribute of that name,...
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
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 CopyTo(TiXmlElement *target) const
void SetAttribute(const char *name, const char *_value)
Sets an attribute of name to a given value.
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
const char * GetText() const
Convenience function for easy access to the text inside an element.
void operator=(const TiXmlElement &base)
TiXmlHandle Child(const char *value, int index) const
Return a handle to the "index" child with the given name.
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
TiXmlHandle FirstChild() const
Return a handle to the first child node.
TiXmlHandle ChildElement(const char *value, int index) const
Return a handle to the "index" child element with the given name.
The parent class for everything in the Document Object Model.
int Type() const
Query the type (as an enumerated value, above) of this node.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
friend class TiXmlDocument
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
void SetValue(const char *_value)
Changes the value of the node.
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
TiXmlNode(NodeType _type)
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
void Clear()
Delete all the children of this node. Does not affect 'this'.
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
NodeType
The types of XML nodes supported by TinyXml.
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
const TiXmlNode * LastChild() const
void CopyTo(TiXmlNode *target) const
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
friend class TiXmlElement
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
const TIXML_STRING & ValueTStr() const
Print to memory functionality.
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
void SetStreamPrinting()
Switch over to "stream printing" which is the most dense formatting without linebreaks.
const std::string & Str()
Return the result.
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
A stylesheet reference looks like this:
void CopyTo(TiXmlStylesheetReference *target) const
TiXmlStylesheetReference()
Construct an empty declaration.
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
void operator=(const TiXmlStylesheetReference ©)
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
virtual TiXmlNode * Clone() const
Creates a copy of this StylesheetReference and returns it.
void CopyTo(TiXmlText *target) 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 TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
bool CDATA() const
Queries whether this represents text using a CDATA section.
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
TiXmlText(const char *initValue)
Constructor for text element.
Any tag that tinyXml doesn't recognize is saved as an unknown.
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
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 Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
void CopyTo(TiXmlUnknown *target) const
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks.
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
FILE * TiXmlFOpen(const char *filename, const char *mode)
std::istream & operator>>(std::istream &in, TiXmlNode &base)
std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)
const TiXmlEncoding TIXML_DEFAULT_ENCODING
const unsigned char TIXML_UTF_LEAD_0
const unsigned char TIXML_UTF_LEAD_1
const unsigned char TIXML_UTF_LEAD_2