How to use XML writer??

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
KAHIMA
Posts: 19
Joined: Sun Mar 01, 2009 7:44 am

How to use XML writer??

Post by KAHIMA »

I have some data, the type is stringc.

Code: Select all

	
                data3 = found2->getText();
		const char *c_str3 = data3.c_str();
for example the type variable data3 is stringc, and there are 5 others the same type data, I want to write the value from the variabel using xml writer..
I already open the manual but i don't understand how to use it

Code: Select all

virtual void irr::io::IXMLWriter::writeElement  (  const wchar_t *  name,  
  bool  empty = false,  
  const wchar_t *  attr1Name = 0,  
  const wchar_t *  attr1Value = 0,  
  const wchar_t *  attr2Name = 0,  
  const wchar_t *  attr2Value = 0,  
  const wchar_t *  attr3Name = 0,  
  const wchar_t *  attr3Value = 0,  
  const wchar_t *  attr4Name = 0,  
  const wchar_t *  attr4Value = 0,  
  const wchar_t *  attr5Name = 0,  
  const wchar_t *  attr5Value = 0 
 )  
How can I implement my variable to xml writer?
Thanks before
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I'm curious to know why you haven't even tried anything. If you have, you should post what you've tried and what you got, as well as what you want. Regardless, I believe that the following code...

Code: Select all

xml->writeElement(L"name", false, L"attr", L"value");
should generate the following xml...

Code: Select all

<name attr="value"/>
Instead of using core::stringc when dealing with the xml writer, you should probably use core::stringw.

Travis
Arcoroc
Posts: 51
Joined: Wed Oct 01, 2008 11:40 pm
Location: Canada

Post by Arcoroc »

With a quick example:

Code: Select all

// ---
bool XmlWriterExample()
{
	// some variable
	core::stringw characterName = L"Dom Fernando" ;

	// init writer
	irr::io::IXMLWriter* writer =  irrlichtDevice->getFileSystem()->createXMLWriter( targetFilePath )  ;
	if ( !writer ) { return false; } 

	// write xml header
	writer->writeXMLHeader(); 

	// write root node
	writer->writeElement( L"MyXmlRootNode",false); 
	writer->writeLineBreak(); 

	// write some variable
	writer->writeElement(L"CharacterName",true, L"value", characterName ); 
	writer->writeLineBreak(); 

	// close root node
	writer->writeClosingTag(L"MyXmlRootNode"); 
	writer->writeLineBreak(); 

	// dispose writer
	writer->drop() ; writer = 0 ;
	return true ;
}
L/
KAHIMA
Posts: 19
Joined: Sun Mar 01, 2009 7:44 am

Post by KAHIMA »

I get something trouble when I used this

Code: Select all

writer->writeElement(L"CharacterName",false, L"value", characterName);
where characterName is variable that used to save text...
core::stringw characterName = "Hai";

but when I use this

Code: Select all

writer->writeElement(L"CharacterName",false, L"value", L"characterName");
there are no error...
the question is how can i save a text that saved before in variable... for example core::stringw characterName = "Hai"; ??
thanks[/code]
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

try this-

Code: Select all

writer->writeElement(L"CharacterName",false, L"value", characterName.c_str());
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
KAHIMA
Posts: 19
Joined: Sun Mar 01, 2009 7:44 am

Post by KAHIMA »

thank you...:)
KAHIMA
Posts: 19
Joined: Sun Mar 01, 2009 7:44 am

Post by KAHIMA »

when i run this code, the first xml data was replaced by the second xml data, and the second replaced by the third, how i can make the xml data that the previous data will not replace by the newest one??
Arcoroc
Posts: 51
Joined: Wed Oct 01, 2008 11:40 pm
Location: Canada

Post by Arcoroc »

KAHIMA wrote:when i run this code, the first xml data was replaced by the second xml data, and the second replaced by the third, how i can make the xml data that the previous data will not replace by the newest one??
Unless you have worked it out since you last wrote, you could try and post your code so that it may help spot the problem.
L/
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

It sounds like you want to append xml data to a file. You cannot do this directly using Irrlicht. You need to read the existing xml, and then write it back out, and then write the data you want to add.

Travis
Post Reply