IXMLReader from stringw

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
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

IXMLReader from stringw

Post by Arclamp »

Hi,

Is it possible to create a IXMLReader from a stringw or such like?

e.g. instead of this

Code: Select all

 
io::IXMLReader *xml = device->getFileSystem()->createXMLReader(fn);
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IXMLReader from stringw

Post by CuteAlien »

You would have to create a memory read file and from that create the xml reader. The memory read file can be created from the memory of a string. At least in theory (I didn't try).
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
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: IXMLReader from stringw

Post by Arclamp »

Hmm ok, thanks
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: IXMLReader from stringw

Post by Arclamp »

Think I may have been down a similar road before... but it isn't parsing, any idea?

Code: Select all

 
io::IXMLReader *createXMLReaderFromString(stringw fs)
{
    irr::u32 c = fs.size();
    
    irr::core::irrAllocator<wchar_t> a;
    wchar_t* m = a.allocate(c);
    
    for(irr::u32 i = 0; i < c; i++)
    {
        m[i] = fs[i];
    }
    
    IReadFile* f = device->getFileSystem()->createMemoryReadFile(
        m, // buffer
        c, // length
        "myfile.xml",
        true /* this should delete my m on drop */);
    
    return device->getFileSystem()->createXMLReader(f);
}
 
void xml_test_02()
{
    stringw fs = L"<data><entry attr=\"1\" /><enter /></data>";
    io::IXMLReader *xml = createXMLReaderFromString(fs);
    
    //io::path fn = "test.xml";
    //io::IXMLReader *xml = device->getFileSystem()->createXMLReader(fn);
    
    while(xml && xml->read())
    {
        std::wcout << "name: " << xml->getNodeName() << std::endl;
    }
    
    xml->drop();
}
 
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: IXMLReader from stringw

Post by Arclamp »

:D

Code: Select all

 
    irr::core::irrAllocator<irr::fschar_t> a;
    irr::fschar_t* m = a.allocate(c);
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IXMLReader from stringw

Post by CuteAlien »

So works now?
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
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: IXMLReader from stringw

Post by Arclamp »

Yuss, working code! Thankyou
Last edited by Arclamp on Fri Mar 16, 2018 5:07 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IXMLReader from stringw

Post by CuteAlien »

Nice :-)
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
Post Reply