# HG changeset patch # User Paul Boddie # Date 1219959307 -7200 # Node ID e1e59e85f84180c5772437b1cc491edbcb6178b0 # Parent 1cb2cf8468c6287eca8d321fd23d2c0ed821c043 Fixed validation examples so that the DTDs are themselves valid. Added filename, line and message information to validation exceptions. Made the error messages more informative. diff -r 1cb2cf8468c6 -r e1e59e85f841 libxml2dom/errors.py --- a/libxml2dom/errors.py Tue Aug 26 00:34:42 2008 +0200 +++ b/libxml2dom/errors.py Thu Aug 28 23:35:07 2008 +0200 @@ -40,6 +40,6 @@ return "DOMError(%d, %r, %r)" % (self.severity, self.message, self.type) def __str__(self): - return repr(self) + return "DOMError: %s" % self.message # vim: tabstop=4 expandtab shiftwidth=4 diff -r 1cb2cf8468c6 -r e1e59e85f841 libxml2dom/macrolib/macrolib.py --- a/libxml2dom/macrolib/macrolib.py Tue Aug 26 00:34:42 2008 +0200 +++ b/libxml2dom/macrolib/macrolib.py Thu Aug 28 23:35:07 2008 +0200 @@ -537,9 +537,9 @@ def __str__(self): exctype, excdata = self.args[0:2] if exctype == self.PARSE_ERR: - return "Parse error: %r" % self + return "Parse error: %s" % excdata elif exctype == self.SERIALIZE_ERR: - return "Serialize error: %r" % self + return "Serialize error: %s" % excdata else: return repr(self) @@ -606,8 +606,17 @@ # NOTE: May not be the correct exception. + error = libxml2mod.xmlGetLastError() + if error is not None: + filename = libxml2mod.xmlErrorGetFile(error) + line = libxml2mod.xmlErrorGetLine(error) + error_message = libxml2mod.xmlErrorGetMessage(error).strip() + message = "Filename %r, line %d: %s" % (filename, line, error_message) + else: + message = "Document did not validate" + raise LSException(LSException.PARSE_ERR, - DOMError(DOMError.SEVERITY_FATAL_ERROR, "Document did not validate")) + DOMError(DOMError.SEVERITY_FATAL_ERROR, message)) elif unfinished or Parser_well_formed(context): return doc diff -r 1cb2cf8468c6 -r e1e59e85f841 tests/test_invalid.xml --- a/tests/test_invalid.xml Tue Aug 26 00:34:42 2008 +0200 +++ b/tests/test_invalid.xml Thu Aug 28 23:35:07 2008 +0200 @@ -1,5 +1,7 @@ + +