Page 1 of 1

need example please. writing to XML file

Posted: Sun May 02, 2004 6:49 pm
by Wolf Dreamer
I'm not sure why, but I seem to be having a lot of difficulty getting this to work.

Will someone please post some code I can use to write to an XML file.

I get nothing but errors when I try to copy and paste things from http://irrlicht.sourceforge.net/docu/cl ... riter.html

I found a misprint in the API

Posted: Mon May 03, 2004 1:35 pm
by Wolf Dreamer
http://irrlicht.sourceforge.net/docu/cl ... eader.html
The code for parsing this file would look like this:

io::IXMLReader* xml = device->getFileSystem()->createXMLReader("config.xml");
Device should be capitalized otherwise it causes an error.

Getting the reader to work isn't a problem, since there is an example in the Meshviewer code, as well as on the API list. I'm still having trouble with the writer though.

I just got this error:
h:\irrlicht-0.6\include\IXMLWriter.h(19) : see declaration of 'irr::io::IXMLWriter'
I put in include IXMLWriter.h in the meshviewer code, thinking perhaps that was the problem. Nope. It doesn't like that either.

Posted: Mon May 03, 2004 2:05 pm
by Wolf Dreamer
h:\irrlicht-0.6\examples\9.Meshviewer\main.cpp(344) : error C2761: 'void irr::io::IXMLWriter::writeXMLHeader(void)' : member function redeclaration not allowed
Someone please tell me what I'm doing wrong. I got everything else working fine I think. No matter what I put in the () it doesn't work.

Eagerly awaiting a reply. I'm sure someone has got the XML writer to work by now... hopefully.

Posted: Mon May 03, 2004 6:32 pm
by kakTuZ
Hi,
the xml-reader is used in the Mesh-viewer example. And in the documentation is the same example.
Be sure you save your xml-file as unicode otherwise he can't read the EOF and repeats infinit the last code (thats the mistake i did :? )
And if your problems still exist youre welcome to post a bit more of your code

greetings
Maxi

Posted: Mon May 03, 2004 6:45 pm
by Wolf Dreamer
I have no problems with the READER. I just need to know how to use the WRITER.

I just posted the spelling error for the reader in my post asking about the writer.

Anyway, can you get it to write to a new XML file? If so, please post some code.

Posted: Tue May 18, 2004 2:14 pm
by jox
Here's some code:

Code: Select all

io::IXMLWriter* xml = Device->getFileSystem()->createXMLWriter("file.xml");
	
xml->writeXMLHeader();
xml->writeLineBreak();

xml->writeComment(L"This is a Comment");
xml->writeLineBreak();

xml->writeElement(L"Element1", false);
xml->writeText(L"Text");
xml->writeClosingTag(L"Element1");
xml->writeLineBreak();

xml->writeElement(L"Element2", true, L"Attr1", L"Val1");
It creates a (unicode) file with the following content:

Code: Select all

<?xml version="1.0"?>

<!--This is a Comment-->
<Element1>Text</Element1>
<Element2 Attr1="Val1" />
Easy? :)

regards,
jox

Posted: Tue May 18, 2004 2:27 pm
by Tyn
And it isn't a spelling mistake for device to be spelt without a capitol, it's a pointer. The pointer could be myGameDevice and it would do the same thing.

Posted: Tue May 18, 2004 2:37 pm
by jox
exactly!

Posted: Tue May 18, 2004 4:29 pm
by jox
One little addition to my code example.

Don't forget to add the following at the end. (Because you're using a 'create' function (see docs for grab()/drop())).:

Code: Select all

xml->drop();

Posted: Tue May 18, 2004 5:10 pm
by Wolf Dreamer
13 minutes after my last post someone actually replied. Ack! Why didn't I notice that before?

Anyway, thanks. That works.

Anxiety willing, one of these days I'll actually get something finished.