I am still learning c++ and need some help reading the contents of an xml file.
Here's the format of my xml file:
<Rotary>
<UserInformation>
<Name>myName</Name>
<Age>myAge</Age>
</UserInformation>
</Rotary>
My c++ program needs to read the values of Name and Age so that I can check it on a SQL DB. I'm really struggling with using tinyxml. Someone gave me some code to try to help me, but I'm still not getting it. Here's the code below:
TiXmlHandle docHandle(&doc);
string tinyData = "null";
TiXmlNode* tinySet = docHandle.FirstChild("Rotary").FirstChild("UserInformation").ToNode();
if (tinySet)
{
for (TiXmlNode* tinyChild = tinySet->FirstChild(); tinyChild; tinyChild = tinyChild->NextSibling())
{
if (tinyChild)
{
if (tinyChild->TINYXML_ELEMENT != tinyChild->Type())
{
continue;
}
//TODO: Change this to reflect my xml structure. Past this point I'm not sure what I'm doing.
tinyData = tinyChild->ToElement()->Attribute("Name");
if (strcmp(tinyData.c_str(), "Name") == 0)
{
localName = tinyChild->ToElement()->FirstChild()->Value();
}
else if (strcmp(tinyData.c_str(), "Age") == 0)
{
localAge = tinyChild->ToElement()->FirstChild()->Value();
}
}
}
}
Any help would be greatly appreciated!