XML reader not reading -_-

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
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

XML reader not reading -_-

Post by trollger »

Im trying to load an XML file and Im just stumped as to what I am doing wrong. Here is the code to load the xml

Code: Select all

SettingsData *ResourceLoader::LoadSettings(){
 
    SettingsData *return_me = new SettingsData();
 
    IrrlichtDevice *null_device = createDevice(video::EDT_NULL);
    IXMLReader *xml_reader = null_device->getFileSystem()->createXMLReader(L"../Data/config.xml");
 
    //keep track of our current section
    stringw currentSection = L"";
 
    //while there is more to read
    while(xml_reader->read()){
        //check the node type
        switch (xml_reader->getNodeType()){
            //we found a new element
            case irr::io::EXN_ELEMENT:{
                if (currentSection.empty()){
                    currentSection = xml_reader->getNodeName();
                }
                // we are at the end of the current section assignment, now read in the tags themselves
                else if (stringw(L"video").equals_ignore_case(xml_reader->getNodeName())){
                    return_me->ResolutionWidth = xml_reader->getAttributeValueAsInt(L"resolution_width");
                    return_me->ResolutionHeight = xml_reader->getAttributeValueAsInt(L"resolution_height");
                    return_me->AntiAiliasingLevel = xml_reader->getAttributeValueAsInt(L"anti_ailiasing");
                    return_me->Fullscreen = xml_reader->getAttributeValueAsInt(L"fullscreen");
                    return_me->Vsync = xml_reader->getAttributeValueAsInt(L"vsync");
                    return_me->DriverType = video::EDT_OPENGL;
                }
            }
            break;
 
            //we found the end of an element
            case irr::io::EXN_ELEMENT_END:
                //we were at the end of the video section so we reset our tag
                currentSection=L"";
            break;
        }
    }
    // don't forget to delete the xml reader & device
    xml_reader->drop();
    null_device->closeDevice();
    null_device->drop();
 
    return return_me;
}
and here is the xml fie

Code: Select all

<?xml version="1.0"?>
<root>  <video resolution_width="1280" resolution_height="720" anti_ailiasing="0" fullscreen="0" vsync="0" /></root>
The thing is that its not even reading the file xml_reader->read() always returns false despite the file path and device being valid.

The really wierd part about all of this is that I am loading XML files elsewhere in my code in the exact same fasion. I even made sure theat the encoding of all of the files UTF-32LE. Im really failing to see what I am doing wrong, it seems that the XML reader just does not want to load this file... any one got any ideas? Are there any common mistakes that I may have made with the XML reader?
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: XML reader not reading -_-

Post by randomMesh »

trollger wrote:The thing is that its not even reading the file xml_reader->read() always returns false despite the file path and device being valid.
Try this, just to be sure:

Code: Select all

 
    //....
 
    IXMLReader *xml_reader = null_device->getFileSystem()->createXMLReader(L"../Data/config.xml");
    if (!xml_reader)
    {
       printf("Omg, invalid path!\n");
    }
 
    //.....
 
"Whoops..."
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Re: XML reader not reading -_-

Post by trollger »

yup tried that, the path is valid.
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: XML reader not reading -_-

Post by CuteAlien »

I don't see anything wrong (aside from a typo - it's "antialiasing"). Maybe compile Irrlicht in debug and step into the read() with the debugger. If you're not familiar with that, the easiest way is usually: Add the Irrlicht project file to your solution. Compile it in debug. Set a breakpoint on the read() line. Then use step-into when the debuggers stops there.
You can remove the Irrlicht project from your solution again when you are done (though I usually just keep it - more fun to be able to step into the engine to see what's going on anyway and you tend to need that often in larger projects).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Re: XML reader not reading -_-

Post by trollger »

Ya I probably should have set that up earlier. Ill get back to you guys once I get that working.
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: XML reader not reading -_-

Post by zerochen »

hi,

i think you have to replace

Code: Select all

if(currentSection.empty())
with

Code: Select all

if (currentSection.empty() && stringw(L"video").equals_ignore_case(xml->getNodeName()))
otherwise you set currentSection to root and the next else if is never true

regards
zerochen
Post Reply