[XML-SIG] PubIdResolver

Marco Machmer marco@morca.de
Thu, 28 Nov 2002 09:38:58 +0100

On Friday, 1. November 2002 22:20, Martin v. Loewis wrote:
> Marco Machmer <marco@morca.de> writes:
> > i want set my own PubIdResolver for an xml-parser created with
> > sax2exts.XMLValParserFactory.make_parser()
> > has anybody a tip for me, how can i do this?
> You should invoke setEntityResolver, passing an object that implements
> the EntityResolver interface (see handler.EntityResolver).
> HTH,
> Martin

it doesn't work for me. here is my example code:
import sys
from xml.sax import sax2exts
from xml.dom.ext.reader import Sax2
from xml.sax.handler import EntityResolver
from xml.dom.ext import PrettyPrint

class MMEntityResolver(EntityResolver):
    def resolveEntity(self, publicId, systemId):
        """Resolve the system identifier of an entity and return either
        the system identifier to read from as a string, or an InputSource
        to read from."""
        print "MMEntityResolver: ich bin da"
        print "publicId: " + str(publicId)
        print "systemId: " + str(systemId)
        if str(publicId) == "-//marco/gg//DE":
            return open("test.dtd", 'r')
        return systemId

myparser = sax2exts.XMLValParserFactory.make_parser()
er = MMEntityResolver()
xreader = Sax2.Reader(parser=myparser)

xf = open(sys.argv[1], 'r')
myDom = xreader.fromStream(xf)



i get the following exception:

  File "dom2.py", line 28, in ?
    myDom = xreader.fromStream(xf)
  File "/usr/lib/python2.1/site-packages/_xmlplus/dom/ext/reader/Sax2.py", line 373, in fromStream
  File "/usr/lib/python2.1/site-packages/_xmlplus/sax/xmlreader.py", line 123, in parse
  File "/usr/lib/python2.1/site-packages/_xmlplus/sax/drivers2/drv_xmlproc.py", line 93, in feed
  File "/usr/lib/python2.1/site-packages/_xmlplus/parsers/xmlproc/xmlval.py", line 44, in feed
  File "/usr/lib/python2.1/site-packages/_xmlplus/parsers/xmlproc/xmlutils.py", line 332, in feed
  File "/usr/lib/python2.1/site-packages/_xmlplus/parsers/xmlproc/xmlproc.py", line 101, in do_parse
  File "/usr/lib/python2.1/site-packages/_xmlplus/parsers/xmlproc/xmlproc.py", line 509, in parse_doctype
  File "/usr/lib/python2.1/site-packages/_xmlplus/parsers/xmlproc/xmlutils.py", line 125, in parse_resource
    self.report_error(3000, sysID)
  File "/usr/lib/python2.1/site-packages/_xmlplus/parsers/xmlproc/xmlutils.py", line 524, in report_error
  File "/usr/lib/python2.1/site-packages/_xmlplus/sax/drivers2/drv_xmlproc.py", line 226, in fatal
    self._err_handler.fatalError(saxlib.SAXParseException(msg, None, self))
  File "/usr/lib/python2.1/site-packages/_xmlplus/dom/ext/reader/Sax2.py", line 341, in fatalError
    raise exception
xml.sax._exceptions.SAXParseException: d1.xml:2:57: Couldn't open resource 'xtest.dtd'


and here my xml-doc:

<?xml version = "1.0"?>
<!DOCTYPE ADDRBOOK PUBLIC "-//marco/gg//DE" "xtest.dtd">
        <ENTRY ID="gn">
                <NAME>Gegbefuna Nwannem</NAME>
                <ADDRESS>666 Murtala Mohammed Blvd.</ADDRESS>
                <PHONENUM DESC="Home">999-101-1001</PHONENUM>

any ideas

Marco Machmer

Phone : +49-2638-94 666 4
Fax   : +49-2638-94 666 7
email : mailto:marco@morca.de
www   : http://www.Marco-Machmer.de 
Um ein tadelloses Mitglied einer Schafherde
sein zu koennen, muss man vor allem ein Schaf sein.
Albert Einstein