Reading XML files with irrXML

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Reading XML files with irrXML

Post by sudi »

maybe its just me but i can't find a good explanation about how to write
an xml file.

Ok this is the programm code to read the file:

Code: Select all

void CXML::LoadConfig(char* File = "Data/config.xml")
{
          IrrXMLReader* xml = createIrrXMLReader(File);

     while(xml && xml->read())
	{
		switch(xml->getNodeType())
		{
		case EXN_ELEMENT:
			
				if (!strcmp("screenx", xml->getNodeName()))
                config.x = xml->getAttributeValueAsInt("x");
                else
                if (!strcmp("screeny", xml->getNodeName()))
                config.y = xml->getAttributeValueAsInt("y");
                break;
		}
	}

	// delete the xml parser after usage
	delete xml;
	
}
and this is the xml file.

Code: Select all

<?xml version="1.0"?>
<config>

<screenx x="1024" />
<screeny y="768" />

</config>
I'm really lost with this and would like some help...
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

does really nobody knows what i'm doing wrong or how i could do it?
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
hybrid

Post by hybrid »

So you have code and data, where's your problem. Would be good to poin out your problems, errors received etc.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Thats the point their is no compile error it compieles but it wont read the data.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
hybrid

Post by hybrid »

I don't see where you defined the config variable. Might be a problem with its scope. Try to output the config variable before returning from your reading function in order to check for correct values.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

what?
sry but i dint catch that....what should i do?
Isn't there someone out here who already did this and could help with a modification in my code?
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
hybrid

Post by hybrid »

You have a struct (probably object of some class) named config in your code. You refer to config.x and config.y in the lines you read the attributes. This object has to be created somewhere. It apparently is because otherwise your app would crash, but it could be destroyed before you can access the values. This depends on the way you create this object. So try to output the values of config.x and config.y at the end of your posted method. That way you can check if the values are correctly read from the file. If so there is something wrong with the config object. If not you have to fix the way of reading attributes.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Ok i already did that so there must be a problem with reading the attributes
but i don't know where the problem is.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
hybrid

Post by hybrid »

Does it enter the if statement, i.e. is at some point the strcmp successful such that Attribute method is called? Does getNodeName return char* or wchar_t* ?
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

should return char* cause i use the extern irrxml parser.
but i don't know if the atribute methode is called. it doesn't return code errors it only doesn't do anything
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
hybrid

Post by hybrid »

Just add a cout to both if statements (and don't forget curly braces) to check if they are reached. And add -Wall (or equivalent) to your compiler options to avoid too simple errors.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

its not working.......there is no output at all.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
hybrid

Post by hybrid »

So it's not with the attribute reading, but the XML parser does not reach the correct node. Check the API and examples if you have to add some default handling for the other nodes of your file. Maybe add output to the main loop to check which nodes are visited and which are not.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Thanks hybrid but u aren't helping...lol....why isn't this working??????AHHHHHHH
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

Did you close the xml tag? i.e. last line should be "</xml>" otherwise I don't think the parser can grab anything out of the xml
Post Reply