help with xml parser

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

help with xml parser

Post 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?
ru guo ni yao ai, ni jiang bu hui shi qu
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post 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
Last edited by area51 on Tue Feb 22, 2011 1:00 pm, edited 1 time in total.
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

Post by rogerdv »

Tried unicode 16 but got a segfault.
ru guo ni yao ai, ni jiang bu hui shi qu
yin nadie
Posts: 43
Joined: Wed Mar 31, 2004 1:03 pm
Location: Seville, Spain
Contact:

Post 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
ANO

Re: help with xml parser

Post 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.
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post 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.
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post 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
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

All elements with the form of <element>, <element .> or </element> come up under either EXN_ELEMENT or EXN_ELEMENT_END.
ANO

Post 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?
Post Reply