71 namespace RTT {
namespace marsh {
73 bool TiXmlBase::condenseWhiteSpace =
true;
86 while( i<(
int)str.length() )
88 unsigned char c = (
unsigned char) str[i];
91 && i < ( (
int)str.length() - 2 )
105 while ( i<(
int)str.length()-1 )
107 outString->append( str.c_str() + i, 1 );
115 outString->append( entity[0].str, entity[0].strLength );
120 outString->append( entity[1].str, entity[1].strLength );
125 outString->append( entity[2].str, entity[2].strLength );
128 else if ( c ==
'\"' )
130 outString->append( entity[3].str, entity[3].strLength );
133 else if ( c ==
'\'' )
135 outString->append( entity[4].str, entity[4].strLength );
144 #if defined(TIXML_SNPRINTF) 145 TIXML_SNPRINTF( buf,
sizeof(buf),
"&#x%02X;", (
unsigned) ( c & 0xff ) );
147 sprintf( buf,
"&#x%02X;", (
unsigned) ( c & 0xff ) );
152 outString->append( buf, (
int)strlen( buf ) );
159 *outString += (char) c;
169 buffer =
new char[ str.length()+1 ];
172 strcpy( buffer, str.c_str() );
265 if ( !beforeThis || beforeThis->
parent !=
this )
273 node->
next = beforeThis;
275 if ( beforeThis->
prev )
284 beforeThis->
prev = node;
291 if ( !afterThis || afterThis->
parent !=
this )
299 node->
prev = afterThis;
301 if ( afterThis->
next )
310 afterThis->
next = node;
317 if ( replaceThis->
parent !=
this )
327 if ( replaceThis->
next )
332 if ( replaceThis->
prev )
345 if ( removeThis->
parent !=
this )
351 if ( removeThis->
next )
356 if ( removeThis->
prev )
370 if ( strcmp( node->
Value(), _value ) == 0 )
382 if ( strcmp( node->
Value(), _value ) == 0 )
394 if ( strcmp( node->
Value(), _value ) == 0 )
405 if ( strcmp( node->
Value(), _value ) == 0 )
419 assert( previous->
parent ==
this );
432 assert( previous->
parent ==
this );
445 assert( previous->
parent ==
this );
458 assert( previous->
parent ==
this );
466 for ( node =
next; node; node = node->
next )
468 if ( strcmp( node->
Value(), _value ) == 0 )
477 for ( node =
next; node; node = node->
next )
479 if ( strcmp( node->
Value(), _value ) == 0 )
488 for ( node =
prev; node; node = node->
prev )
490 if ( strcmp( node->
Value(), _value ) == 0 )
499 for ( node =
prev; node; node = node->
prev )
501 if ( strcmp( node->
Value(), _value ) == 0 )
513 attributeSet.Remove( node );
635 for( node =
this; node; node = node->
parent )
647 for( node =
this; node; node = node->
parent )
697 while( attributeSet.
First() )
700 attributeSet.
Remove( node );
712 return node->
Value();
771 #if defined(TIXML_SNPRINTF) 772 TIXML_SNPRINTF( buf,
sizeof(buf),
"%d", val );
774 sprintf( buf,
"%d", val );
783 std::ostringstream oss;
793 #if defined(TIXML_SNPRINTF) 794 TIXML_SNPRINTF( buf,
sizeof(buf),
"%f", val );
796 sprintf( buf,
"%f", val );
817 attributeSet.
Add( attrib );
840 attributeSet.
Add( attrib );
854 for ( i=0; i<depth; i++ )
856 fprintf( cfile,
" " );
859 fprintf( cfile,
"<%s",
value.c_str() );
862 for ( attrib = attributeSet.
First(); attrib; attrib = attrib->
Next() )
864 fprintf( cfile,
" " );
865 attrib->Print( cfile, depth );
875 fprintf( cfile,
" />" );
879 fprintf( cfile,
">" );
881 fprintf( cfile,
"</%s>",
value.c_str() );
885 fprintf( cfile,
">" );
891 fprintf( cfile,
"\n" );
893 node->
Print( cfile, depth+1 );
895 fprintf( cfile,
"\n" );
896 for( i=0; i<depth; ++i )
897 fprintf( cfile,
" " );
898 fprintf( cfile,
"</%s>",
value.c_str() );
904 (*stream) <<
"<" <<
value;
907 for ( attrib = attributeSet.
First(); attrib; attrib = attrib->
Next() )
924 (*stream) <<
"</" << value <<
">";
941 for( attribute = attributeSet.
First();
943 attribute = attribute->
Next() )
973 return childText->
Value();
983 useMicrosoftBOM =
false;
990 useMicrosoftBOM =
false;
991 value = documentName;
1000 useMicrosoftBOM =
false;
1001 value = documentName;
1009 copy.CopyTo(
this );
1016 copy.CopyTo(
this );
1056 FILE* file = fopen(
value.c_str (),
"rb" );
1060 bool result =
LoadFile( file, encoding );
1085 fseek( file, 0, SEEK_END );
1086 length = ftell( file );
1087 fseek( file, 0, SEEK_SET );
1099 data.reserve( length );
1122 char* buf =
new char[ length+1 ];
1125 if ( fread( buf, length, 1, file ) != 1 ) {
1130 const char* lastPos = buf;
1131 const char* p = buf;
1135 assert( p < (buf+length) );
1139 data.append( lastPos, (p-lastPos+1) );
1142 assert( p <= (buf+length) );
1144 else if ( *p == 0xd ) {
1147 if ( (p-lastPos) > 0 ) {
1148 data.append( lastPos, p-lastPos );
1152 if ( *(p+1) == 0xa ) {
1156 assert( p <= (buf+length) );
1162 assert( p <= (buf+length) );
1171 data.append( lastPos, p-lastPos );
1176 Parse( data.c_str(), 0, encoding );
1188 FILE* fp = fopen( filename,
"w" );
1201 if ( useMicrosoftBOM )
1207 fputc( TIXML_UTF_LEAD_0, fp );
1208 fputc( TIXML_UTF_LEAD_1, fp );
1209 fputc( TIXML_UTF_LEAD_2, fp );
1220 target->error = error;
1221 target->errorDesc = errorDesc.c_str ();
1247 node->
Print( cfile, depth );
1248 fprintf( cfile,
"\n" );
1311 if (
value.find (
'\"') == TIXML_STRING::npos)
1312 fprintf (cfile,
"%s=\"%s\"", n.c_str(), v.c_str() );
1314 fprintf (cfile,
"%s='%s'", n.c_str(), v.c_str() );
1320 if (
value.find(
'\"' ) != TIXML_STRING::npos)
1323 (*stream) <<
"=" <<
"'";
1330 (*stream) <<
"=" <<
"\"";
1338 if ( sscanf(
value.c_str(),
"%d", ival ) == 1 )
1345 if ( sscanf(
value.c_str(),
"%lf", dval ) == 1 )
1353 #if defined(TIXML_SNPRINTF) 1354 TIXML_SNPRINTF(buf,
sizeof(buf),
"%d", _value);
1356 sprintf (buf,
"%d", _value);
1364 #if defined(TIXML_SNPRINTF) 1365 TIXML_SNPRINTF( buf,
sizeof(buf),
"%lf", _value);
1367 sprintf (buf,
"%lf", _value);
1374 return atoi (
value.c_str ());
1379 return atof (
value.c_str ());
1398 for (
int i=0; i<depth; i++ )
1400 fputs(
" ", cfile );
1402 fprintf( cfile,
"<!--%s-->",
value.c_str() );
1407 (*stream) <<
"<!--";
1437 fprintf( cfile,
"\n" );
1438 for ( i=0; i<depth; i++ ) {
1439 fprintf( cfile,
" " );
1441 fprintf( cfile,
"<![CDATA[" );
1442 fprintf( cfile,
"%s",
value.c_str() );
1443 fprintf( cfile,
"]]>\n" );
1449 fprintf( cfile,
"%s", buffer.c_str() );
1458 (*stream) <<
"<![CDATA[" <<
value <<
"]]>";
1470 target->cdata = cdata;
1488 const char * _encoding,
1489 const char * _standalone )
1493 encoding = _encoding;
1494 standalone = _standalone;
1498 #ifdef TIXML_USE_STL 1500 const std::string& _encoding,
1501 const std::string& _standalone )
1505 encoding = _encoding;
1506 standalone = _standalone;
1527 fprintf (cfile,
"<?xml ");
1529 if ( !version.empty() )
1530 fprintf (cfile,
"version=\"%s\" ", version.c_str ());
1531 if ( !encoding.empty() )
1532 fprintf (cfile,
"encoding=\"%s\" ", encoding.c_str ());
1533 if ( !standalone.empty() )
1534 fprintf (cfile,
"standalone=\"%s\" ", standalone.c_str ());
1535 fprintf (cfile,
"?>");
1540 (*stream) <<
"<?xml ";
1542 if ( !version.empty() )
1544 (*stream) <<
"version=\"";
1548 if ( !encoding.empty() )
1550 (*stream) <<
"encoding=\"";
1552 (*stream ) <<
"\" ";
1554 if ( !standalone.empty() )
1556 (*stream) <<
"standalone=\"";
1568 target->version = version;
1569 target->encoding = encoding;
1570 target->standalone = standalone;
1588 for (
int i=0; i<depth; i++ )
1589 fprintf( cfile,
" " );
1590 fprintf( cfile,
"<%s>",
value.c_str() );
1596 (*stream) <<
"<" <<
value <<
">";
1620 sentinel.next = &sentinel;
1621 sentinel.prev = &sentinel;
1627 assert( sentinel.next == &sentinel );
1628 assert( sentinel.prev == &sentinel );
1636 addMe->next = &sentinel;
1637 addMe->prev = sentinel.prev;
1639 sentinel.prev->next = addMe;
1640 sentinel.prev = addMe;
1647 for( node = sentinel.next; node != &sentinel; node = node->next )
1649 if ( node == removeMe )
1651 node->prev->next = node->next;
1652 node->next->prev = node->prev;
1665 for( node = sentinel.next; node != &sentinel; node = node->next )
1667 if ( node->name == name )
1677 for( node = sentinel.next; node != &sentinel; node = node->next )
1679 if ( node->name == name )
1685 #ifdef TIXML_USE_STL 1689 tag.reserve( 8 * 1000 );
1690 base.StreamIn( &in, &tag );
1705 #ifdef TIXML_USE_STL 1708 std::ostringstream os_stream( std::ostringstream::out );
1711 out.append( os_stream.str() );
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
double DoubleValue() const
Return the value of this attribute, converted to a double.
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
virtual TiXmlNode * Clone() const
Create an exact duplicate of this node and return it.
const char * Name() const
Return the name of this attribute.
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
friend TIXML_OSTREAM & operator<<(TIXML_OSTREAM &out, const TiXmlNode &base)
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
virtual void StreamOut(TIXML_OSTREAM *out) const
const char * Value() const
Return the value of this attribute.
void Clear()
Delete all the children of this node. Does not affect 'this'.
void SetIntValue(int _value)
Set the value from an integer.
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream.
void CopyTo(TiXmlUnknown *target) const
void RemoveAttribute(const char *name)
Deletes an attribute with the given name.
std::istream & operator>>(std::istream &is, BufferPolicy &bp)
virtual void StreamOut(TIXML_OSTREAM *) const =0
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
TiXmlElement(const char *in_value)
Construct an element.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
virtual void StreamOut(TIXML_OSTREAM *out) const
void operator=(const TiXmlDocument ©)
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
static void PutString(const TIXML_STRING &str, TIXML_OSTREAM *out)
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
An attribute is a name-value pair.
Always the top level node.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
void operator=(const TiXmlDeclaration ©)
void operator=(const TiXmlElement &base)
TiXmlHandle FirstChild() const
Return a handle to the first child node.
virtual void StreamOut(TIXML_OSTREAM *out) const
void * userData
Field containing a generic user pointer.
void CopyTo(TiXmlNode *target) const
void Add(TiXmlAttribute *attribute)
TiXmlDeclaration()
Construct an empty declaration.
TiXmlHandle ChildElement(const char *value, int index) const
Return a handle to the "index" child element with the given name.
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
int QueryIntAttribute(const char *name, int *_value) const
QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer...
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
void SetDoubleValue(double _value)
Set the value from a double.
TiXmlNode(NodeType _type)
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
int QueryIntValue(int *_value) const
QueryIntValue examines the value string.
virtual void StreamOut(TIXML_OSTREAM *out) const
const TiXmlAttribute * Find(const TIXML_STRING &name) const
virtual void Print(FILE *cfile, int depth) const =0
All TinyXml classes can print themselves to a filestream.
virtual void Print(FILE *cfile, int depth) const
Print this Unknown to a FILE stream.
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
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 SetValue(const char *_value)
Changes the value of the node.
void Print() const
Dump the document to standard out.
The parent class for everything in the Document Object Model.
const TiXmlAttribute * First() const
virtual void Print(FILE *cfile, int depth) const
Print this declaration to a FILE stream.
TiXmlBase is a base class for every class in TinyXml.
TiXmlDocument()
Create an empty document, that has no name.
StringToBuffer(const TIXML_STRING &str)
virtual void StreamOut(TIXML_OSTREAM *out) const
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
The element is a container class.
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
void ClearError()
If you have handled the error, it can be reset with this call.
TiXmlHandle Child(const char *value, int index) const
Return a handle to the "index" child with the given name.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
const TiXmlEncoding TIXML_DEFAULT_ENCODING
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
const unsigned char TIXML_UTF_LEAD_0
virtual void Print(FILE *cfile, int depth) const
Write this text object to a FILE stream.
const unsigned char TIXML_UTF_LEAD_1
int IntValue() const
Return the value of this attribute, converted to an integer.
const TiXmlNode * LastChild() const
void CopyTo(TiXmlElement *target) const
bool Error() const
If an error occurs, Error will be set to true.
void Remove(TiXmlAttribute *attribute)
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
const unsigned char TIXML_UTF_LEAD_2
void SetValue(const char *_value)
Set the value.
const char * GetText() const
Convenience function for easy access to the text inside an element.
void CopyTo(TiXmlText *target) const
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
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.
In correct XML the declaration is the first entry in the file.
NodeType
The types of XML nodes supported by TinyXml.
Any tag that tinyXml doesn't recognize is saved as an unknown.
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
virtual void StreamOut(TIXML_OSTREAM *out) const
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
void SetAttribute(const char *name, const char *_value)
Sets an attribute of name to a given value.
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
void CopyTo(TiXmlDeclaration *target) const
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.