Sign in to follow this  
MARS_999

XML reading issue help needed

Recommended Posts

Update nevermind it works already... SIgh!!!

 

 

 

I am not sure how to iterate over this XML document to get all the <tileset> fields so I can know at load time how many images to load?

 

Here is what I have but only reads the first set of data from the firstgid attribute

 

THis I can read and is all I get 

////

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="256" height="256" tilewidth="64" tileheight="64">
 <tileset firstgid="1" name="mud" tilewidth="64" tileheight="64">
  <image source="Mud.png" width="640" height="640"/>
 </tileset>
 

 

but I need to read something like this where I can load all tileset fields.

/// here is the many tileset data sets

 

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="256" height="256" tilewidth="64" tileheight="64">
 <tileset firstgid="1" name="mud" tilewidth="64" tileheight="64">
  <image source="Mud.png" width="640" height="640"/>
 </tileset>
 <tileset firstgid="101" name="water" tilewidth="64" tileheight="64">
  <image source="Water.png" width="640" height="640"/>
 </tileset>
 <tileset firstgid="201" name="grass" tilewidth="64" tileheight="64">
  <image source="Grass.png" width="640" height="640"/>
 </tileset>
 
 
//tileset header
for (const tinyxml2::XMLElement* child = doc.FirstChildElement("map")->FirstChildElement("tileset");
child != 0; child = child->NextSiblingElement())
{
if (child->Attribute("firstgid"))
{
std::cout << "firstgid = " << child->Attribute("firstgid") << std::endl;
}
if (child->Attribute("name"))
{
std::cout << "name = " << child->Attribute("name") << std::endl;
}
if (child->Attribute("tilewidth"))
{
std::cout << "tilewidth = " << child->Attribute("tilewidth") << std::endl;
}
if (child->Attribute("tileheight"))
{
std::cout << "tileheight = " << child->Attribute("tileheight") << std::endl;
}
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this