Reputation: 1
I'm trying to load an XML file in with tinyxml and I'm not sure what to do. I'm new to tinyxml and XML file loading in general and was looking for some help. I managed to get the root using the RootElement function, as well as the first child element and its attribute. The problem is, the next line in the XML doesn't have an attribute (or at least I don't think it's called an attribute) and I don't know how to load the number. To clarify, my XML looks sort of like this:
<?xml version="1.0" encoding="utf-8"?>
<Name name="temp">
<NumLine>125</NumLine>
<Font>12</Font>
My question is, how do I store the value 125 in this line <NumLine>125</NumLine>
? Like I said, I'm really new to this and can't figure out what to do so any help would be greatly appreciated.
Upvotes: 0
Views: 2457
Reputation: 1010
To get the value stored between , you would need to use the NextSiblingElement() function.
Here is a basic code setup to load data from XML
TiXmlDocument doc("document.xml");
bool loadOkay = doc.LoadFile(); // Error checking in case file is missing
if(loadOkay)
{
TiXmlElement *pRoot = doc.RootElement();
TiXmlElement *element = pRoot->FirstChildElement();
while(element)
{
string value = firstChild->Value(); // In your example xml file this gives you ToDo
string attribute = firstChild->Attribute("time"); //Gets you the time variable
element = element->NextSiblingElement();
}
}
else
{
//Error conditions
}
Upvotes: 0