• Advertisement
Sign in to follow this  

XML reading issue help needed

This topic is 1304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement