Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

TinyXML2 help on loading simple .xml files

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 MARS_999   Members   

1621
Like
0Likes
Like

Posted 29 July 2012 - 06:56 PM

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...


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();
}


#2 Ashaman73   Members   

13714
Like
0Likes
Like

Posted 29 July 2012 - 11:55 PM

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]

Ashaman

 

Gnoblins: Website - Facebook - Twitter - Youtube - Steam Greenlit - IndieDB - Gamedev Log


#3 MARS_999   Members   

1621
Like
0Likes
Like

Posted 30 July 2012 - 06:33 PM

Nope still doesn't work, tried that first and no luck... :(




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.