Page 1 of 1

irrXML reading error

Posted: Mon Jun 26, 2006 8:21 am
by krama757
Greetings, I would like the community's help with one of my simple xml parsing errors.
The xml document named default.xml is:
<?xml version="1.0"?>

<map numObjects="0" addWater="1">
<heightmap>./data/maps/HM-257.jpg</heightmap>
<texturemap>./data/textures/maps/HM-257.bmp</texturemap>
<detailmap>./data/textures/env/detailmap.jpg</detailmap>
</map>
IE parses it fine and doesnt return any errors.

The in-game reading is done using:
cout<<"Filename to be opened by loadMap: "<<fileName<<endl;
IXMLReaderUTF8* irrReader = irrDevice->getFileSystem()->createXMLReaderUTF8(fileName);
if(irrReader == 0)
cout<<"File couldnt be opened for reading...xml"<<endl;

string<c8> heightMap;
string<c8> textureMap;
string<c8> detailMap;
int numObjects;
int addWater;

while(irrReader && irrReader->read()){
switch(irrReader->getNodeType()){
case EXN_TEXT:
if(!strcmp("heightmap", irrReader->getNodeName())) //!strcmp is the same as strcmp == 0
heightMap = irrReader->getNodeData();
if(!strcmp("texturemap", irrReader->getNodeName()))
textureMap = irrReader->getNodeData();
if(!strcmp("detailmap", irrReader->getNodeName()))
detailMap = irrReader->getNodeData();
break;
case EXN_ELEMENT:
if(!strcmp("map", irrReader->getNodeName())){
numObjects = irrReader->getAttributeValueAsInt("numObjects");
addWater = irrReader->getAttributeValueAsInt("addWater");
}
break;
}
}

cout<<"Weee: "<<heightMap.c_str()<<endl;

delete irrReader;
I know IrrReader is initialized and the file is found because the irrReader != 0.

For some reason nothing is read into the variables heightMap, textureMap, nor any of the others. Is there is a reason for this?

Posted: Mon Jun 26, 2006 1:46 pm
by bitplane
the reason is you're comparing a pointer to a L"multi-byte" char array to a pointer to a "single-byte" char array, use the wide char srting compare (wstrcmp?) and prefix your strings with L, or if you are not comfortable with arrays and stuff, convert to a nice multi-byte string object like the example given in the docs for IrrXML

Posted: Mon Jun 26, 2006 3:47 pm
by krama757
I see, but doesnt the IXMLReaderUTF8 return char * ? Only the original IXMLReader() returned wchat_t*, no?