25 #ifndef _MADARA_NO_XML_
36 FILE*
TiXmlFOpen(
const char* filename,
const char* mode );
41 FILE*
TiXmlFOpen(
const char* filename,
const char* mode )
43 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
45 errno_t err = fopen_s( &fp, filename, mode );
50 return fopen( filename, mode );
58 while( i<(
int)str.length() )
60 unsigned char c = (
unsigned char) str[i];
63 && i < ( (
int)str.length() - 2 )
77 while ( i<(
int)str.length()-1 )
79 outString->append( str.c_str() + i, 1 );
100 else if ( c ==
'\"' )
102 outString->append(
entity[3].str,
entity[3].strLength );
105 else if ( c ==
'\'' )
107 outString->append(
entity[4].str,
entity[4].strLength );
116 #if defined(TIXML_SNPRINTF)
117 TIXML_SNPRINTF( buf,
sizeof(buf),
"&#x%02X;", (
unsigned) ( c & 0xff ) );
119 sprintf( buf,
"&#x%02X;", (
unsigned) ( c & 0xff ) );
124 outString->append( buf, (
int)strlen( buf ) );
131 *outString += (char) c;
232 if ( !beforeThis || beforeThis->
parent !=
this ) {
246 node->
next = beforeThis;
248 if ( beforeThis->
prev )
257 beforeThis->
prev = node;
264 if ( !afterThis || afterThis->
parent !=
this ) {
278 node->
prev = afterThis;
280 if ( afterThis->
next )
289 afterThis->
next = node;
299 if ( replaceThis->
parent !=
this )
317 if ( replaceThis->
next )
322 if ( replaceThis->
prev )
339 if ( removeThis->
parent !=
this )
345 if ( removeThis->
next )
350 if ( removeThis->
prev )
364 if ( strcmp( node->
Value(), _value ) == 0 )
376 if ( strcmp( node->
Value(), _value ) == 0 )
391 assert( previous->
parent ==
this );
405 assert( previous->
parent ==
this );
414 for ( node =
next; node; node = node->
next )
416 if ( strcmp( node->
Value(), _value ) == 0 )
426 for ( node =
prev; node; node = node->
prev )
428 if ( strcmp( node->
Value(), _value ) == 0 )
514 for( node =
this; node; node = node->
parent )
578 return node->
Value();
597 const char* result = 0;
600 result = attrib->
Value();
613 const std::string* result = 0;
629 const char* result = 0;
632 result = attrib->
Value();
645 const std::string* result = 0;
762 for ( i=0; i<depth; i++ ) {
763 fprintf( cfile,
" " );
766 fprintf( cfile,
"<%s",
value.c_str() );
771 fprintf( cfile,
" " );
772 attrib->Print( cfile, depth );
782 fprintf( cfile,
" />" );
786 fprintf( cfile,
">" );
788 fprintf( cfile,
"</%s>",
value.c_str() );
792 fprintf( cfile,
">" );
798 fprintf( cfile,
"\n" );
800 node->
Print( cfile, depth+1 );
802 fprintf( cfile,
"\n" );
803 for( i=0; i<depth; ++i ) {
804 fprintf( cfile,
" " );
806 fprintf( cfile,
"</%s>",
value.c_str() );
821 attribute = attribute->
Next() )
839 if ( !node->Accept( visitor ) )
864 return childText->
Value();
882 value = documentName;
892 value = documentName;
932 bool result =
LoadFile( file, encoding );
957 fseek( file, 0, SEEK_END );
958 length = ftell( file );
959 fseek( file, 0, SEEK_SET );
989 char* buf =
new char[ length+1 ];
992 if ( fread( buf, length, 1, file ) != 1 ) {
1009 const char* p = buf;
1011 const char CR = 0x0d;
1012 const char LF = 0x0a;
1016 assert( p < (buf+length) );
1017 assert( q <= (buf+length) );
1031 assert( q <= (buf+length) );
1034 Parse( buf, 0, encoding );
1063 fputc( TIXML_UTF_LEAD_0, fp );
1064 fputc( TIXML_UTF_LEAD_1, fp );
1065 fputc( TIXML_UTF_LEAD_2, fp );
1068 return (ferror(fp) == 0);
1107 node->Print( cfile, depth );
1108 fprintf( cfile,
"\n" );
1119 if ( !node->Accept( visitor ) )
1174 if (
value.find (
'\"') == TIXML_STRING::npos) {
1176 fprintf (cfile,
"%s=\"%s\"", n.c_str(), v.c_str() );
1179 (*str) += n; (*str) +=
"=\""; (*str) += v; (*str) +=
"\"";
1184 fprintf (cfile,
"%s='%s'", n.c_str(), v.c_str() );
1187 (*str) += n; (*str) +=
"='"; (*str) += v; (*str) +=
"'";
1210 #if defined(TIXML_SNPRINTF)
1213 sprintf (buf,
"%d", _value);
1221 #if defined(TIXML_SNPRINTF)
1224 sprintf (buf,
"%g", _value);
1231 return atoi (
value.c_str ());
1236 return atof (
value.c_str ());
1256 for (
int i=0; i<depth; i++ )
1258 fprintf( cfile,
" " );
1260 fprintf( cfile,
"<!--%s-->",
value.c_str() );
1272 return visitor->
Visit( *
this );
1294 fprintf( cfile,
"\n" );
1295 for ( i=0; i<depth; i++ ) {
1296 fprintf( cfile,
" " );
1298 fprintf( cfile,
"<![CDATA[%s]]>\n",
value.c_str() );
1304 fprintf( cfile,
"%s", buffer.c_str() );
1318 return visitor->
Visit( *
this );
1336 const char * _encoding,
1337 const char * _standalone )
1346 #ifdef TIXML_USE_STL
1348 const std::string& _encoding,
1349 const std::string& _standalone )
1375 if ( cfile ) fprintf( cfile,
"<?xml " );
1376 if ( str ) (*str) +=
"<?xml ";
1379 if ( cfile ) fprintf (cfile,
"version=\"%s\" ",
version.c_str ());
1380 if ( str ) { (*str) +=
"version=\""; (*str) +=
version; (*str) +=
"\" "; }
1383 if ( cfile ) fprintf (cfile,
"encoding=\"%s\" ",
encoding.c_str ());
1384 if ( str ) { (*str) +=
"encoding=\""; (*str) +=
encoding; (*str) +=
"\" "; }
1387 if ( cfile ) fprintf (cfile,
"standalone=\"%s\" ",
standalone.c_str ());
1388 if ( str ) { (*str) +=
"standalone=\""; (*str) +=
standalone; (*str) +=
"\" "; }
1390 if ( cfile ) fprintf( cfile,
"?>" );
1391 if ( str ) (*str) +=
"?>";
1407 return visitor->
Visit( *
this );
1425 for (
int i=0; i<depth; i++ )
1426 fprintf( cfile,
" " );
1427 fprintf( cfile,
"<%s>",
value.c_str() );
1439 return visitor->
Visit( *
this );
1471 #ifdef TIXML_USE_STL
1490 if ( node == removeMe )
1503 #ifdef TIXML_USE_STL
1508 if ( node->name == name )
1531 if ( strcmp( node->name.c_str(), name ) == 0 )
1550 #ifdef TIXML_USE_STL
1554 tag.reserve( 8 * 1000 );
1563 #ifdef TIXML_USE_STL
1569 out << printer.
Str();
1580 out.append( printer.
Str() );
1727 for(
const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->
Next() )
1730 attrib->Print( 0, 0, &
buffer );
1843 #endif // _MADARA_NO_XML_
const TiXmlAttribute * First() const
An attribute is a name-value pair.
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
Implements the interface to the "Visitor pattern" (see the Accept() method.) If you call the Accept()...
const std::string & ValueTStr() const
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
bool Error() const
If an error occurs, Error will be set to true.
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.
TiXmlHandle FirstChild() const
Return a handle to the first child node.
void CopyTo(TiXmlUnknown *target) const
void CopyTo(TiXmlDocument *target) const
int Type() const
Query the type (as an enumerated value, above) of this node.
TiXmlAttribute * FindOrCreate(const char *_name)
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 ...
static void EncodeString(const std::string &str, std::string *out)
Expands entities in a string.
void operator=(const TiXmlDeclaration ©)
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
void operator=(const TiXmlDocument ©)
const unsigned char TIXML_UTF_LEAD_2
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
void SetName(const char *_name)
Set the name of this attribute.
virtual void Print(FILE *cfile, int depth, std::string *str) const
TiXmlDocument()
Create an empty document, that has no name.
void ClearError()
If you have handled the error, it can be reset with this call.
const char * Value() const
Return the value of this attribute.
int QueryIntValue(int *_value) const
QueryIntValue examines the value string.
void Clear()
Sets row and column to -1.
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.
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
static bool condenseWhiteSpace
NodeType
The types of XML nodes supported by TinyXml.
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
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
Accept a hierchical visit the nodes in the TinyXML DOM.
void Print() const
Write the document to standard out using formatted printing ("pretty print").
In correct XML the declaration is the first entry in the file.
std::istream & operator>>(std::istream &in, TiXmlNode &base)
TiXmlAttributeSet attributeSet
Any tag that tinyXml doesn't recognize is saved as an unknown.
const TiXmlEncoding TIXML_DEFAULT_ENCODING
void SetDoubleAttribute(const std::string &name, double value)
TiXmlHandle ChildElement(const char *value, int index) const
Return a handle to the "index" child element with the given name.
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)
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)
Deletes an attribute with the given name.
virtual TiXmlNode * Clone() const
Create an exact duplicate of this node and return it.
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 ...
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, std::string *tag)=0
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Always the top level node.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
TiXmlEncoding
Used by the parsing routines.
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 TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
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.
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
Return a handle to the "index" child with the given name.
void Add(TiXmlAttribute *attribute)
const std::string & ValueStr() const
Return the value of this attribute.
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
bool CDATA() const
Queries whether this represents text using a CDATA section.
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
TiXmlBase is a base class for every class in TinyXml.
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
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)
int QueryIntAttribute(const char *name, int *_value) const
QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer...
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
TiXmlNode(NodeType _type)
The parent class for everything in the Document Object Model.
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.
Print to memory functionality.
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().
TiXmlText(const char *initValue)
Constructor for text element.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
void CopyTo(TiXmlText *target) const
void CopyTo(TiXmlElement *target) const
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
const char * GetText() const
Convenience function for easy access to the text inside an element.
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.
const std::string & Str()
Return the result.
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
TiXmlDeclaration()
Construct an empty declaration.
void SetStreamPrinting()
Switch over to "stream printing" which is the most dense formatting without linebreaks.
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.
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 bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
void CopyTo(TiXmlDeclaration *target) const
The element is a container class.
TiXmlCursor errorLocation
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.