Hiya, I dloaded tinyxml last night for a research project. In my own source copy I've added the following extensions to the TiXmlElement class (within tinyxml.h):
bool HasAttribute( const char* name ) const
{
return ( NULL != Attribute( name ) );
}
bool HasAttribute( const char* name, int* i ) const
{
return ( NULL != Attribute( name, i ) );
}
/// Inside the #ifdef TIXML_USE_STL section...
bool HasAttribute( const std::string& name ) const
{
return ( NULL != Attribute( name ) );
}
bool HasAttribute( const std::string& name, int* i ) const
{
return ( NULL != Attribute( name, i ) );
}
I've found these useful in my current project, and maybe it would be useful within the codebase?
Sorry, I'm very new to source-forge so I don't know whether (or even how :) to add these myself.
Maybe they seem pointless to people more used to xml?
Also a quick question, why doesn't tinyxml use namespaces?
Anyway, thanks and it's a great lib. Compiled first time in my project which was unexpected but impressive :)
n!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, I don't think most people mind checking for a NULL return, but it's up to you :) I'd be a bit worried about passing in the int* though... if you're just checking for the presence of an attribute, why store the value as well?
An alternative implementation might be:
bool HasAttribute( const char * name ) const
{
return attributeSet.Find( name ) != 0;
}
And obviously the same sort of thing for std::strings. This cuts out the 'middleman' of the 'Attribute()' ' function, for what little it's worth.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hiya, I dloaded tinyxml last night for a research project. In my own source copy I've added the following extensions to the TiXmlElement class (within tinyxml.h):
bool HasAttribute( const char* name ) const
{
return ( NULL != Attribute( name ) );
}
bool HasAttribute( const char* name, int* i ) const
{
return ( NULL != Attribute( name, i ) );
}
/// Inside the #ifdef TIXML_USE_STL section...
bool HasAttribute( const std::string& name ) const
{
return ( NULL != Attribute( name ) );
}
bool HasAttribute( const std::string& name, int* i ) const
{
return ( NULL != Attribute( name, i ) );
}
I've found these useful in my current project, and maybe it would be useful within the codebase?
Sorry, I'm very new to source-forge so I don't know whether (or even how :) to add these myself.
Maybe they seem pointless to people more used to xml?
Also a quick question, why doesn't tinyxml use namespaces?
Anyway, thanks and it's a great lib. Compiled first time in my project which was unexpected but impressive :)
n!
Well, I don't think most people mind checking for a NULL return, but it's up to you :) I'd be a bit worried about passing in the int* though... if you're just checking for the presence of an attribute, why store the value as well?
An alternative implementation might be:
bool HasAttribute( const char * name ) const
{
return attributeSet.Find( name ) != 0;
}
And obviously the same sort of thing for std::strings. This cuts out the 'middleman' of the 'Attribute()' ' function, for what little it's worth.