0

I'm trying to loop through elements in an HTML document, and pretty much copied and pasted the code from the TinyXML documentation, but this segfaults after it has gone through every child.

std::string html = "<TABLE><TR></TR><TR></TR><TR></TR></TABLE>";
TiXmlDocument doc;
doc.Parse(html.c_str(), 0, TIXML_ENCODING_UTF8);
TiXmlNode *entry = 0;
while (entry = doc.FirstChildElement("TABLE")->IterateChildren(entry))
{                    
    std::cout<<entry<<std::endl;
}

Here's an example of the output:

0x1a2b190
0x1a2b290
0x1a2b360
Segmentation fault (core dumped)

The same thing happens if I loop using NextSiblingElement() instead of IterateChildren(). Why isn't this working?

howard
  • 644
  • 2
  • 7
  • 15
  • I looked at the TinyXML docs, and TiXmlDocument did not show a FirstChildElement() member function. – woolstar Dec 29 '13 at 04:11
  • @woolstar `TiXmlDocument` is a subclass of `TiXmlNode`, which has a `FirstChildElement()` method. – howard Dec 29 '13 at 04:15

0 Answers0