[libxml++] [Patch] problem with TextReader.read()



Hi there,

I'm working with TextReader, and I had some trouble wen playing with 
exceptions. In fact it was a problem in read() function.

Here is the thing, when doing:

    xmlpp::TextReader reader("example.xml");

    while(reader.read())
    {
[...]
    }

and if the xml file has a parse error, it just fall in an infinite loop 
because read() always read the same node.
In fact, according to the xmlTextReaderRead() doc, this function can return -1 
if an error occured, and not just a boolean value.
Attached is a patch to make this work and also throw an exception.

-- 
------------------------
Raoul Hecky
Index: libxml++/parsers/textreader.cc
===================================================================
--- libxml++/parsers/textreader.cc	(révision 192)
+++ libxml++/parsers/textreader.cc	(copie de travail)
@@ -61,8 +61,16 @@
 
 bool TextReader::read()
 {
-  return propertyreader->Bool(
-      xmlTextReaderRead(impl_));
+  int res = xmlTextReaderRead(impl_);
+
+  if( res < 0 )
+  {
+    #ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
+    throw internal_error("An error occured when reading");
+    #endif //LIBXMLCPP_EXCEPTIONS_ENABLED
+  }
+
+  return propertyreader->Bool(res);
 }
 
 Glib::ustring TextReader::read_inner_xml()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]