Page 1 of 1

help with xml parser

Posted: Tue Mar 30, 2004 9:45 pm
by rogerdv
I adapted the sample code to read this:
<?xml version="1.0"?>
<config>
<shadows>no</shadows>
<fullscreen>no</fullscreen>
</config>

the code is this:
io::IXMLReader* xml = device->getFileSystem()->createXMLReader("config2.xml");

core::stringw c_shadows;
core::stringw c_fullsc;
while(xml->read())
{
cout <<"In the while"<<endl;
switch(xml->getNodeType())
{
case io::EXN_TEXT:
cout <<"is a text"<<endl;
if (core::stringw("shadows") == xml->getNodeName()){
c_shadows = xml->getNodeData();
cout << "Found shadows "<<endl;
}
else if (core::stringw("fullscreen") == xml->getNodeName()) {
c_fullsc = xml->getNodeData();
cout << "Found fullscreen "<<endl;
}

break;

}
}

but it justs fall in an endless while loop. What is wrong there?

Posted: Tue Mar 30, 2004 10:49 pm
by area51
The problem is probably with how the xml is stored, at the moment Niko's implementation only seems to work with xml saved as unicode. Notepad with windows 2000 can do this, alternativley you can use another editor such as http://www.pcworlddownload.com/system-u ... d-Lite.htm

Try saving the xml in unicode format first to see if it's this thats causing your problem.
________
Vermont Dispensaries

Posted: Wed Mar 31, 2004 2:32 pm
by rogerdv
Tried unicode 16 but got a segfault.

Posted: Wed Mar 31, 2004 6:25 pm
by yin nadie
It also happened to me. I tried some different formats, but obtained only errors or the endless loop again.

A temporary solution could be adding a node at the end that, when read, ends the parsing proccess. that does work. (I have already done it), but in case of parsing errors the endless loop tends to appear again

Re: help with xml parser

Posted: Sat Aug 28, 2004 8:54 am
by ANO
rogerdv wrote:I adapted the sample code to read this:
Where did you find the sample code? I want to read my config in xml and have the same problem.

Posted: Sat Aug 28, 2004 11:16 am
by Tyn
Right, for the sample you have up there you would end the loop by stopping the while loop when that tag is reached. I use a parsing bool so that I can stop the parsing when I want. Look at this:

Code: Select all

while ( xml-read() && mapParsing == true )
{
	if (xml1->getNodeType() == irr::io::EXN_ELEMENT_END && irr::core::stringw("config") == xml1->getNodeName() )
		mapParsing = false;
}

This will exit the reader when the </config> tag is found. We use this and it seems to work fine with Linux.

Posted: Sat Aug 28, 2004 12:17 pm
by Electron
you call getNodeName() when the element is of type EXN_TEXT. I beleive getNodeName only works on EXN_ELEMENT and EXN_ELEMENT_END

Posted: Sat Aug 28, 2004 1:33 pm
by Tyn
All elements with the form of <element>, <element .> or </element> come up under either EXN_ELEMENT or EXN_ELEMENT_END.

Posted: Sat Aug 28, 2004 8:01 pm
by ANO
ok, and then how to change renderer.

I have this:

Code: Select all


IrrlichtDevice *device =
		createDevice(EDT_NULL, dimension2d<s32>(640, 480), 32, true, false, 0);

core::stringw renderer;

...

if (core::stringw("renderer") == xml->getNodeName()) {
renderer = xml->getNodeData();

...

device = createDevice(renderer, dimension2d<s32>(800, 600), 32, true, false, 0);

How to convert types?