Problem reading XML file [SOLVED]

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
oringe
Posts: 41
Joined: Tue Jul 05, 2011 7:06 am
Location: San Francisco

Problem reading XML file [SOLVED]

Post by oringe »

My XML writer function seems to be working fine, and is producing a file that looks like this:

Code: Select all

    <?xml version="1.0"?>
 
    <attributes>
        <int name="activeLevelNum" value="1" />
        <int name="activeLevelProgress" value="2" />
    </attributes>
But I'm having a problem reading the file. Here is my read function:

Code: Select all

bool kx::LoadGame()
{
    io::path fileName = fileOpenDialog->getFileName(); 
    // current working directory is appropriate
    IXMLReader* reader = fileSys->createXMLReader( fileSys->getFileBasename( fileName ));
    if (!reader)
    {
        cout<< "\nError: couldn't create XML reader :(";
        return false;
    }
    else
    {
        cout<< "\nparser format= "<< reader->getParserFormat(); // outputs 3 (ETF_UTF16_LE)
        cout<< "\nsource format= "<< reader->getSourceFormat(); // outputs 3
 
        while( reader->read() );
        {
            switch( reader->getNodeType() )
            {
            case io::EXN_ELEMENT_END:
                cout<< "\nEnd reached";
                break;
 
            case io::EXN_ELEMENT:
                if( core::stringw(L"attributes") == reader->getNodeName() )
                {
                    // read attributes
                    io::IAttributes* attr = fileSys->createEmptyAttributes( driver );
                    attr->read( reader );
 
                    cout<< "\nactiveLevelNum= "<< attr->getAttributeAsInt( "activeLevelNum" );
 
                    attr->drop();
                }
                break;
 
            default: break;
            }
        }
        reader->drop();
        return true;
    }
}
 
I've experimented with many variations, but I always get output of "End reached" and can not access the values of the elements :(
What am I doing wrong?
Last edited by oringe on Fri Dec 28, 2012 2:37 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem reading XML file

Post by CuteAlien »

You have a semicolon after your while and so it only loops that line. All the stuff between the {} brackets is run _after_ you have read in the complete file already. Remove the semicolon and it should work.
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
oringe
Posts: 41
Joined: Tue Jul 05, 2011 7:06 am
Location: San Francisco

Re: Problem reading XML file

Post by oringe »

Thanks Alien,
Sometimes you just need another set of eyes :D
Post Reply