NextSiblingElement() should do the trick.
It should be noted that using attributes in tinyxml xml is much simpler than using actual child elements.
Code:
<completeAccount>
<accountEntry>
<account name = "AAA" type = "admin"/>
<virtualUser loginName = "BBB" password = "1"/>
</accountEntry>
</completeAccount>
Code:
struct AccountEntry
{
std::string accountName;
std::string accountType;
std::string loginName;
std::string password;
};
typedef std::vector<AccountEntry> entries;
entries accountEntries;
std::ostringstream ostrm;
std::ifstream inFile("myxml.xml");
ostrm << inFile.rdbuf();
TiXmlDocument doc;
doc.Parse(ostrm.str().c_str());
inFile.close();
TiXmlElement *pRoot = doc.RootElement();
if (pRoot)
{
AccountEntry entry;
TiXmlElement *pChild = pRoot->FirstChildElement();
while (pChild)
{
TiXmlElement *pChildNode = pChild->FirstChildElement();
if (pChildNode)
{
entry.accountName = pChildNode->Attribute("name");
entry.accountType = pChildNode->Attribute("type");
}
pChildNode = pChildNode->NextSiblingElement();
if (pChildNode)
{
entry.loginName = pChildNode->Attribute("loginName");
entry.password = pChildNode->Attribute("password");
}
accountEntries.push_back(entry);
pChild = pChild->NextSiblingElement();
}
}
That change in the XML will allow you to read in the items in a while loop and it makes the XML simpler to read. This code is not all that safe from a tinyxml standpoint b/c it assumes it knows the layout of the xml file. There are other functions to use which require you to specify the name of the node you want and also provided error checking if that node does not exist. The methods I used will simply throw exceptions deep in xstring or assembly code and will not give you an indication of the problem.
This code was tested in MSVS 2005 and should work with the example XML.