Sign in to follow this  

TinyXML2 help on loading simple .xml files

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

I am trying to load this .xml file

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<resource UID ="1" type="graphic" filename="mypng.png" scenescope="0"> </resource>
</resources>


with this code but the first loop after if(tree) is skipped and thinking something with the method I am trying to read from the XMLDocument is worng...


[code]
int LoadXMLFile(const std::string& file)
{
tinyxml2::XMLDocument doc;
doc.LoadFile(file.c_str());
tinyxml2::XMLNode* tree = doc.FirstChild();
if(tree)
{
for(tinyxml2::XMLNode* child = tree->FirstChild(); child; child = child->Parent()->NextSibling())
{
tinyxml2::XMLElement* element = child->Parent()->ToElement();
if(element)
{
for(const tinyxml2::XMLAttribute* attribute = element->FirstAttribute();
attribute;
attribute = attribute->Next())
{
std::string attribName = attribute->Name();
std::string attribValue = attribute->Value();
std::cout << attribName << ", " << attribValue << std::endl;
}
}
}
}
else
std::cout << "Error\n";

return doc.ErrorID();
}
[/code]

Share this post


Link to post
Share on other sites
I would leave the parent out:
[source lang="cpp"] for(tinyxml2::XMLNode* child = tree->FirstChild(); child; child = child->NextSibling())
{
tinyxml2::XMLElement* element = child->ToElement();
[/source]

Share this post


Link to post
Share on other sites

This topic is 1960 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this