# TinyXml

## 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));

{
if (node == 0)
return false;

TiXmlNode* sibling = node;

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

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

}


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 on other sites
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 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628314
• Total Posts
2982022

• 9
• 9
• 13
• 11
• 14