Jump to content
  • Advertisement
Sign in to follow this  
Desdemona

TinyXml

This topic is 4860 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

The format for my game's XML file is similar to this: <item id="12345"> <ac dt="int">10</ac> <dr dt="int">2</dr> <enc dt="int">1000</enc> <name dt="string">platemail tunic</name> </item> I wrote some code using MSXML to read in the data and create my game objects, but I'm moving to TinyXml because of some compatibility issues. I'm having trouble with navigating the XML properly with TinyXml. The (incomplete) code below is what I have right now. I'm just trying to get the data displayed in the right order; once I have that, creating the game objects will be easy.
LoadXml(doc.FirstChild(APPNAME));

bool CSDataset::LoadXml(TiXmlNode* node)
{
	if (node == 0)
		return false;

	TiXmlNode* sibling = node;

	do
	{
		sibling = sibling->NextSibling();	
	}
	while (LoadXml(sibling));

	cout << node->Value() << endl;

	return LoadXml(node->FirstChild());
}

The above code creates output that looks like this: item ac 10 dr 2 enc 1000 name platemail tunic This above code does not attempt to display the attributes, which is where my problem is (e.g. the dt="int"). Ideally, I want the output to be this: item id=12345 ac dt=int 10 dr dt=int 2 enc dt=int 1000 name dt=string platemail tunic I can get the attribute pairs from the XML, but I just cant seem to get everything in the correct order. Any help from someone who knows TinyXml would be greatly appriciated... Thanks Joe

Share this post


Link to post
Share on other sites
Advertisement
you need to iterate the attributes

off the top of my head...roughly something like

bool CSDataset::LoadXml(TiXmlNode* node)
{
if (node == 0)
return false;

TiXmlNode* sibling = node;

do
{
sibling = sibling->NextSibling();
}
while (LoadXml(sibling))


cout << node->Value() << endl;
if (TiXmlElement* pElement = node->ToElement())
{
if (TiXmlAttribute* pAttrib = pElement->FirstAttribute())
{
do
{
cout << pAttrib->Value() << endl;
}
while(pAttrib = pAttrib->Next())
}
}

return LoadXml(node->FirstChild());
}




should be enough to get you started

Share this post


Link to post
Share on other sites
Okay, that got me to where I needed to be in a couple seconds flat, thanks a lot. That was only slightly different than one of the ways I had tried before, but I just couldnt get it right.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!