looking for irrxml example

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
iZigoo
Posts: 53
Joined: Fri Feb 23, 2007 1:32 pm

looking for irrxml example

Post by iZigoo »

I am looking for an example how to parse the applied xml file
in irrxml. Maybe somebody has made a similar irrxml code and can help me.Is irrxml a good solution for this or is it better to use
tinyxml ?
I looked in the forums and google but didn`t find any good examples.

Thanks


izigoo

The xml file is this...
just a simple example but it will be extended much more ...


<?xml version="1.0"?>
<izigooscene>
<building>
<iziobject>
<area/>NewCentral
<city/>Chicago
<description/>Room of Martin Banks
<position/>30,-34,300
<rotation/>0,-90,18
<type/>room
<file/>hall1.3ds
</iziobject>

<iziobject>
<area/>NewCentral
<city/>Chicago
<position/>20,34,300
<rotation/>0,90,180
<scale/>1,0.5,1
<type/>chair
<file/>chairbig.3ds
</iziobject>

<iziobject>
<area/>NewCentral
<city/>Berlin
<position/>220,34,300
<rotation/>0,90,180
<scale/>1,0.5,1
<type/>car
<file/>car.3ds
</iziobject>
</building>
</izigooscene>
-------------------------------------------------------
iZigoo - The open 3D internet

iZigoo Homepage
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The single tags won't work this way (with no XML reader, this is no correctly parsable XML). Change them to two tag elements. Then it should work with irrXML.
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

Post by liger13 »

iZigoo
Posts: 53
Joined: Fri Feb 23, 2007 1:32 pm

Post by iZigoo »

Actually i am looking for a concrete example source ...
The tutorial from blindside is a little bit short ...
There must be some users who already used irrxml for bigger
xml files ....

hybrid ...
With single tag do you mean the short cut xml?
like
<area/>NewCentral


<area>NewCentral</area>
is the normal long version i think ....

Hmmm ...
<area/>NewCentral
as much as i know this is also a way to write xml
... just has not so much overhead ...
-------------------------------------------------------
iZigoo - The open 3D internet

iZigoo Homepage
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

Post by liger13 »

heres some code from my game settings class if it helps:
the constructor reads from a file in order to get info,
then the destructor writes the latest config back to the file. (theres probably and easier way todo this but i dono what it is).

Code: Select all

GameSettings::GameSettings()
{
	//open and read config.xml
	IrrlichtDevice *deviceStart = createDevice(); //need to create a device, for one hasnt been made yet when settings() is called.
	
	xml = deviceStart->getFileSystem()->createXMLReader("config.xml");

	while (xml && xml->read())
	{
		if (core::stringw("version") == xml->getNodeName())
		{
			version = xml->getAttributeValue(L"number");
		}
		else if (core::stringw("player") == xml->getNodeName())
		{
			playerNum = xml->getAttributeValueAsInt(L"currentPlayer");
		}
		else if (core::stringw("driver") == xml->getNodeName())
		{
			windowWidth = xml->getAttributeValueAsInt(L"windowWidth");
			windowHeight = xml->getAttributeValueAsInt(L"windowHeight");
			fullscreen = xml->getAttributeValueAsInt(L"fullscreen");
			driverType = (video::E_DRIVER_TYPE)xml->getAttributeValueAsInt(L"driver");
		}
	}
	
	deviceStart->drop();
	xml->drop();
	ifInMenu = true;
	ifInGame = false;

	change = false;
	restart_bool = false;
	type = 0;
}

GameSettings::~GameSettings()
{
	//write latest config to config.xml
	io::IXMLWriter * xmlWrite = device->getFileSystem()->createXMLWriter("config.xml");
	xmlWrite->writeXMLHeader();
	xmlWrite->writeElement(L"config");
	xmlWrite->writeLineBreak();
		xmlWrite->writeComment(L" Driver settings: 0 = openGL, 1 = Direct 3D 9.c ");
		xmlWrite->writeLineBreak();
		xmlWrite->writeElement(L"version", true, L"number", version.c_str());
		xmlWrite->writeLineBreak();
		xmlWrite->writeLineBreak();
		xmlWrite->writeComment(L" current player(1-3) ");
		xmlWrite->writeLineBreak();
		xmlWrite->writeElement(L"player",true, L"currentPlayer",core::stringw(playerNum).c_str());
		xmlWrite->writeLineBreak();
		xmlWrite->writeLineBreak();
		xmlWrite->writeComment(L"drivers: 4= directx 9, 5= opengl");
		xmlWrite->writeLineBreak();
		xmlWrite->writeElement(L"driver", true, L"windowWidth", core::stringw(windowWidth).c_str(), L"windowHeight", core::stringw(windowHeight).c_str(), L"fullscreen", core::stringw((int)fullscreen).c_str(), L"driver", core::stringw((int)driverType).c_str());
	xmlWrite->writeLineBreak();
	xmlWrite->writeClosingTag(L"config");
	xmlWrite->drop();
	//clean memory
	delete player1;
}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

iZigoo wrote: <area>NewCentral</area>
is the normal long version i think ....

Hmmm ...
<area/>NewCentral
as much as i know this is also a way to write xml
... just has not so much overhead ...
The short version does not work. The tag is closed and done when you find the string, so the string goes into the parent tag. That's not what you'd expect...
Post Reply