IrrXML nodes to int
IrrXML nodes to int
Hi,
I've got a xml file, example:
<root>
<child>
<value>21</value>
<value2>213</value>
<value3>4125</value>
<value4>2183</value>
</child>
</root>
I want to get the integer values of them.
Is there an easy way to do this?
Or more specifically, is there a way to convert const wchar_t* (or stringw, or stringc) to integer?
I've got a xml file, example:
<root>
<child>
<value>21</value>
<value2>213</value>
<value3>4125</value>
<value4>2183</value>
</child>
</root>
I want to get the integer values of them.
Is there an easy way to do this?
Or more specifically, is there a way to convert const wchar_t* (or stringw, or stringc) to integer?
Re: IrrXML nodes to int
nander wrote: Or more specifically, is there a way to convert const wchar_t* (or stringw, or stringc) to integer?
Code: Select all
int _wtoi(const wchar_t *str);
Re: IrrXML nodes to int
I tried that one.. _wchar is not declared in this scope.. It seems to be only for MS. C++, not for linux (GCC). Or are they in a seperate library (apart from <string.h>greenya wrote:nander wrote: Or more specifically, is there a way to convert const wchar_t* (or stringw, or stringc) to integer?(c) http://msdn.microsoft.com/en-us/library ... S.80).aspxCode: Select all
int _wtoi(const wchar_t *str);
I've used this http://www.cplusplus.com/reference/clib ... dlib/atoi/
I tried atoi.. Cannot convert error..Tihtinen wrote:I've used this http://www.cplusplus.com/reference/clib ... dlib/atoi/
Doesn't atoi require a const char*, instead of a const wchar_t*?
For some reason it just doesn't seem to work nice.. Why on earth does getNodeData return a const char_t*? why not just a const char*?
I start with this:
core::stringw test;
test = xml->getNodeData();
//And I want to end with:
int integer = // ...//
What code should be placed in between?
If you really must convert a wchar_t string to an integer, then you should either convert the wchar_t string to a char string, and then use atoi(), strtol(), strtoul() or strtod(), or you could write your own routine to do it directly. The solution would be trivial if you reformatted your xml to use xml attributes. A simple call to reader->getAttributeValueAsInt() would do the trick. An even better solution would be to use the Irrlicht IAttributes interface for reading and writing your xml data.
Travis
Travis
I'll try the getAttributeValueAsInt. I read of it before, but now I've made up my mind.. I first thought the XML would look terrible, but it doesn't look that bad. So I'll do it that way.. Thanks all.vitek wrote:If you really must convert a wchar_t string to an integer, then you should either convert the wchar_t string to a char string, and then use atoi(), strtol(), strtoul() or strtod(), or you could write your own routine to do it directly. The solution would be trivial if you reformatted your xml to use xml attributes. A simple call to reader->getAttributeValueAsInt() would do the trick. An even better solution would be to use the Irrlicht IAttributes interface for reading and writing your xml data.
Travis
Edit: Why does getAttributeValueAsInt return a const char*?
-- Solved it.. I missed a 'L'
Edit::
if (!strcmp("model", xml->getNodeName())) doesn't work for some reason (http://www.ambiera.com/irrxml/docu/index.html)
It gives an error (converting const wchar_t* to const char*).
I used to use Irrlicht 1.6.. I never ran into any wchar errors.. Why on earth do all those functions exit wchar variables?
The function strcmp() is declared like this...nander wrote:if (!strcmp("model", xml->getNodeName())) doesn't work for some reason (http://www.ambiera.com/irrxml/docu/index.html)
It gives an error (converting const wchar_t* to const char*).
I used to use Irrlicht 1.6.. I never ran into any wchar errors.. Why on earth do all those functions exit wchar variables?
Code: Select all
extern "C" {
int strcmp (const char* s1, const char* s2);
}
When you call the function like this...
Code: Select all
strcmp("model", xml->getNodeName())
Travis
STL?
I know that STL is not suppose to be used with irrlicht but I usually do that:
If I didn't do any typo this should work on any OS sporting STL in the world. Some people will argue about performance issue but if you read XML files just once, who care!
Code: Select all
#include <sstream>
#include <string>
[...]
// your pointer to a wchar_t string
wchar_t* p;
// your return int
int i;
// convert STL style
{
std::wstringstream ss(p);
ss >> i;
}