#include "tinyXml/tinyxml.h" const char MY_XML[] = "<?xml version='1.0' standalone=no><main> <ToDo time='1'> <Item priority='1'> Go to the <bold>Toy store!</bold></Item> <Item priority='2'> Do bills</Item> </ToDo> <ToDo time='2'> <Item priority='1'> Go to the Second<bold>Toy store!</bold></Item> </ToDo></main>"; void main() { TiXmlDocument doc; TiXmlHandle docHandle(&doc); const char * const the_xml = MY_XML; doc.Parse(MY_XML); TiXmlElement* xElement = NULL; xElement = docHandle.FirstChild("main").FirstChild("ToDo").ToElement(); int element_time = -1; while(xElement) { if(xElement->QueryIntAttribute("time", (int*)&element_time) != TIXML_SUCCESS) throw; xElement = xElement->NextSiblingElement(); } }
How it works. Compiled and tested.
Since you can see that your attempts to make code with extra code cost you with exceotion on your third line (question), and without testing, I can argue with this "pointing to null" exception.
Just load my style as TinyXml docs say: "docHandle.FirstChild (" main "). FirstChild (" ToDo "). ToElement ();".
Hope this helps you understand, let me know if this is not clear. I accept visas (:
source share