Page 1 of 1
IXMLReader from stringw
Posted: Thu Mar 15, 2018 11:56 pm
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);
Re: IXMLReader from stringw
Posted: Fri Mar 16, 2018 12:19 am
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).
Re: IXMLReader from stringw
Posted: Fri Mar 16, 2018 12:33 am
by Arclamp
Hmm ok, thanks
Re: IXMLReader from stringw
Posted: Fri Mar 16, 2018 1:01 am
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();
}
Re: IXMLReader from stringw
Posted: Fri Mar 16, 2018 1:45 am
by Arclamp
Code: Select all
irr::core::irrAllocator<irr::fschar_t> a;
irr::fschar_t* m = a.allocate(c);
Re: IXMLReader from stringw
Posted: Fri Mar 16, 2018 11:09 am
by CuteAlien
So works now?
Re: IXMLReader from stringw
Posted: Fri Mar 16, 2018 12:50 pm
by Arclamp
Yuss, working code! Thankyou
Re: IXMLReader from stringw
Posted: Fri Mar 16, 2018 1:03 pm
by CuteAlien
Nice :-)