[XML-SIG] Patch for xmlproc: proper SAX error-handling in validating parsers

uche.ogbuji@fourthought.com uche.ogbuji@fourthought.com
Sun, 18 Oct 1998 10:45:20 -0700


This is a multipart MIME message.

--==_Exmh_-16799825460
Content-Type: text/plain; charset=us-ascii

I know that Lars is off for the month, and I've been investigating a problem 
where the SAX driver for the validating xmlproc parser was not calling the 
appropriate SAX driver functions for error handling:  It was instead using the 
xmlproc API report_error method, which simply prints the error to stdout.  I 
needed a proper SAXException or SAXParseException generated and passed to the 
SAX ErrorHandler error or fatalError method.

I found what appears to be the problem, and I have a patch (attached) for 
xml.sax.drivers.drv_xmlproc_val.py
that fixes it.  I hope that until Lars returns

a)	It helps someone else having the same problems with SAX/xmlproc error 
reporting as I had.
b)	Others can test and make sure it works for them and doesn't break other 
things.

Thanks.

-- 
Uche Ogbuji
uche.ogbuji@fourthought.com
Consulting Member, FourThought LLC
http://FourThought.com		http://OpenTechnology.org
(970)481-0805


--==_Exmh_-16799825460
Content-Type: text/plain; name="valdrv_error_patch.diff"; charset=us-ascii
Content-Description: valdrv_error_patch.diff
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="valdrv_error_patch.diff"

*** drv_xmlproc_val.py	Sun Oct 18 10:42:16 1998
--- uche/drv_xmlproc_val.py	Sun Oct 18 02:40:08 1998
***************
*** 5,11 ****
  version=3D"0.91"
  =

  from xml.sax import saxlib,saxutils
! from xml.parsers.xmlproc import xmlval
  from xml.sax.drivers.drv_xmlproc import *
  =

  import types
--- 5,11 ----
  version=3D"0.91"
  =

  from xml.sax import saxlib,saxutils
! from xml.parsers.xmlproc import xmlval, errors
  from xml.sax.drivers.drv_xmlproc import *
  =

  import types
***************
*** 19,27 ****
  	self.parser.set_error_handler(self)
          self.dtd=3Dself.parser.get_dtd()
  	self.doc_handler.setDocumentLocator(self)
!     =

      def _create_parser(self):
! 	return xmlval.XMLValidator()
  =

      def handle_start_tag(self, name, attrs):
          try:
--- 19,31 ----
  	self.parser.set_error_handler(self)
          self.dtd=3Dself.parser.get_dtd()
  	self.doc_handler.setDocumentLocator(self)
! 	#needed to placate xmlval.XMLValidator.handle_doctype    =

! 	self.errors =3D errors.english
! =

      def _create_parser(self):
! 	validator =3D xmlval.XMLValidator()
! 	validator.val.parser =3D self
! 	return validator
  =

      def handle_start_tag(self, name, attrs):
          try:
***************
*** 30,35 ****
--- 34,43 ----
                                                         self.dtd.get_ele=
m(name)))
          except KeyError,e:
              self.doc_handler.startElement(name,XPAttributes(attrs,None)=
)
+ =

+     def report_error(self, msg, param):
+ 	message =3D (self.errors[msg])%(param)
+ 	self.error(message)
              =

      # --- EXPERIMENTAL PYTHON SAX EXTENSIONS:
  =


--==_Exmh_-16799825460--