I use this lib for a new project and i like her, because she is very simple to use.
But i want to know if something is implemented for case insensitive parsing, because i want that "exemple" can match with "Exemple". I now that I can convert attribut or anything else in lower or upper case and do the comparaison but I don't like this methode. I searching something simple and faster.
Sorry for my bad english, i am french.
Ps : It's my first post on sourceforge.net (I like this community open source)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
TinyXML does not support any case-insesitive behavior.
Case insensitive isn't the XML way - all elements and attributes are case sensitive. Difficulty is a big factor: UTF-8 globalized case-insensitive compares are really hard. English is easy; French is difficult; beyond that can be truly hard. (UTF-8 tolower() and toupper() is only a partial solution.)
lee
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't now if you have understand that I want my code can see "exemple" like "Exemple", but in the xml file tag must be exactly the same.
ex : <Exemple>test</Exemple>
but in my code there is no difference between "exemple" and "Exemple".
the function MyAttribute protect string to a potential NULL return;
string MyAttribute(TiXmlElement *pElement, string sAttribute)
{
const char *tmp; // for protect string to NULL return
string sCurrentAttribute;
TiXmlAttribute *pCurrentAttribute;
int iStop;
The first thing to know, which Lee mentioned, is that you are fighting the system. XML (and therefore tinyxml) uses case. That means that Example and example and EXAMPLE and eXaMpLe are all different. End of story.
Now, if you want to go against it, you can expect some pain.
So I'd suggest a first stop of asking "do I TRULY need to say that example and EXAMPLE are the same?" because most other xml developers don't need this.
Having said this, is what you are trying to achieve something like
I use this lib for a new project and i like her, because she is very simple to use.
But i want to know if something is implemented for case insensitive parsing, because i want that "exemple" can match with "Exemple". I now that I can convert attribut or anything else in lower or upper case and do the comparaison but I don't like this methode. I searching something simple and faster.
Sorry for my bad english, i am french.
Ps : It's my first post on sourceforge.net (I like this community open source)
TinyXML does not support any case-insesitive behavior.
Case insensitive isn't the XML way - all elements and attributes are case sensitive. Difficulty is a big factor: UTF-8 globalized case-insensitive compares are really hard. English is easy; French is difficult; beyond that can be truly hard. (UTF-8 tolower() and toupper() is only a partial solution.)
lee
I have finaly find a solution, i use stl::transform methode for convert strings in lower case and i made the comparaison.
Thx for our precision.
I don't now if you have understand that I want my code can see "exemple" like "Exemple", but in the xml file tag must be exactly the same.
ex : <Exemple>test</Exemple>
but in my code there is no difference between "exemple" and "Exemple".
the function MyAttribute protect string to a potential NULL return;
string MyAttribute(TiXmlElement *pElement, string sAttribute)
{
const char *tmp; // for protect string to NULL return
string sCurrentAttribute;
TiXmlAttribute *pCurrentAttribute;
int iStop;
transform(sAttribute.begin(), sAttribute.end(), sAttribute.begin(), tolower);
for (pCurrentAttribute = pElement->FirstAttribute(), iStop = 0;
!iStop && pCurrentAttribute;
pCurrentAttribute = pCurrentAttribute->Next())
{
iStop = 0;
tmp = pCurrentAttribute->Name();
if (tmp)
{
sCurrentAttribute = tmp;
transform(sCurrentAttribute.begin(), sCurrentAttribute.end(),
sCurrentAttribute.begin(), tolower);
if (sCurrentAttribute == sAttribute)
{
iStop = 1;
tmp = pCurrentAttribute->Value();
if (tmp)
return tmp;
return "";
}
}
}
return "";
}
int InsensitiveCmp(string sValue1, string sValue2)
{
transform(sValue1.begin(), sValue1.end(), sValue1.begin(), tolower);
transform(sValue2.begin(), sValue2.end(), sValue2.begin(), tolower);
return (sValue1 == sValue2);
}
The first thing to know, which Lee mentioned, is that you are fighting the system. XML (and therefore tinyxml) uses case. That means that Example and example and EXAMPLE and eXaMpLe are all different. End of story.
Now, if you want to go against it, you can expect some pain.
So I'd suggest a first stop of asking "do I TRULY need to say that example and EXAMPLE are the same?" because most other xml developers don't need this.
Having said this, is what you are trying to achieve something like
doc.LoadFile()
pElement = doc.FirstElementCaseI("example")
?
in which case, rather than converting strings, why not just add a method that uses stricmp instead of strcmp?
>in which case, rather than converting strings, why not just add a method that uses stricmp instead of strcmp?
I don't know, i can do both but I don't kown whom methode is the faster. I don't have made test.