Qt and Rapidxml , empty node causes crash while parsing



I'm using Qt and the rapidxml library.



xml_document<> doc;
doc.parse<0>(&stream[0]);
xml_node<> *first = doc.first_node();
xml_node<> *second = first->first_node("book");
xml_node<> *third = second->first_node("description");
xml_node<> *cdata = third->first_node();
stream = cdata->value();
return stream;


this is the body of a function that gets the description out of the xml and everything works fine when the xml has all the data. Sometimes though the xml has no description data and ,instead of just an empty node, is like this:



<language_code>eng</language_code>
<is_ebook>false</is_ebook>
<description/>
<publication_year>1993</publication_year>


so when I assign the value to stream the program crashes and while debugging the debugger shows me this method of the rapidxml header:



Ch *value() const
{
return m_value ? m_value : nullstr();
}


I do not know how to fix this. Is any exception thrown?Is a null string being returned? Thanks in advance.


No comments:

Post a Comment