I'm trying to implement a simple xml-reader in c++ using libxml++. So far i've manged to open the xml-document, print the relevant parts and then exit. the problem is that i get a segmentation fault when exiting.
Code:
int main()
{
Glib::ustring file_name = "test.xml";
xmlpp::DomParser test(file_name);
xmlpp::Document* test_xml = test.get_document();
xmlpp::Element* root_node = test_xml->get_root_node();
xmlpp::Element::NodeList children = root_node->get_children(Glib::ustring("item"));
xmlpp::Element::NodeList::iterator i;
i = children.begin();
while (i != children.end())
{
xmlpp::Element::NodeList item_list = (*i)->get_children(Glib::ustring("title"));
xmlpp::Element::NodeList::iterator g;
g = item_list.begin();
while (g!=item_list.end())
{
if (xmlpp::Element((*g)->cobj()).has_child_text())
{
xmlpp::Element test((*g)->cobj());
cout << (test.get_child_text())->get_content() << endl;
}
g++;
}
i++;
}
}
Is there something missing? Do i have to close the specific document in some way? gdb outputs:
Code:
#0 0x40243eaf in _int_free () from /lib/libc.so.6
#1 0x40242cdf in free () from /lib/libc.so.6
#2 0x4017cd75 in operator delete (ptr=0x433318)
at ../../../../gcc-3.3.3/libstdc++-v3/libsupc++/del_op.cc:39
#3 0x400ee2cf in xmlpp::NonCopyable::~NonCopyable ()
from /usr/lib/libxml++-2.6.so.1
#4 0x400ed588 in (anonymous namespace)::on_libxml_destruct ()
from /usr/lib/libxml++-2.6.so.1
#5 0x4037d200 in xmlFreeNodeList () from /usr/lib/./libxml2.so.2
#6 0x4037d0c1 in xmlFreeNodeList () from /usr/lib/./libxml2.so.2
#7 0x4037d0c1 in xmlFreeNodeList () from /usr/lib/./libxml2.so.2
#8 0x4037ad2d in xmlFreeDoc () from /usr/lib/./libxml2.so.2
#9 0x400ed86b in xmlpp::Document::~Document () from /usr/lib/libxml++-2.6.so.1
#10 0x0804901b in main () at test.cpp:36
so obviously there is something wrong with how the destructor works?