[XML-SIG] PyXML 0.8.3 problem on windows...

Radovan Chytracek Radovan.Chytracek at cern.ch
Tue Sep 30 11:21:26 EDT 2003


    so when I applied the fix I propose in PyXML bug report #814935, see


I could write SAX EntityResolver and I did not get any exception
anymore. The following code shows that use-case. I tested it on my
modified PyXML 0.8.3 installation using Win32 Python 2.2.3 .

I would suggest to provide InputSource variant (if no such exists yet),
which allows to construct SAX reader InputSource from a string or
UNICODE buffer for convenience in such situations as is this one.



-------------- cut & paste from here -------------
import xml.sax

inmemdtd = u"""
<!-- This is the fake DTD
     which has no physical file and exists
     only in this form and XML file can
     refer to it as:
     <!DOCTYPE mydoc SYSTEM "internal.dtd">
<!ELEMENT mydoc (empty)>

inmemdoc = u"""<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mydoc SYSTEM "internal.dtd">
<mydoc />

def Str2Stream( cstr ):
    from cStringIO import StringIO
    return StringIO( cstr )

class MyEntityResolver(xml.sax.handler.EntityResolver):
    def resolveEntity(self, publicId, systemId):
        # The bogus DTD external entity so do it as in C++
        dtdbuf    = Str2Stream( inmemdtd )
        dtdSource =  xml.sax.xmlreader.InputSource()
        dtdSource.setByteStream( dtdbuf )
        dtdSource.setSystemId( systemId )
        return dtdSource

if __name__ == '__main__':
    xmldoc = Str2Stream( inmemdoc.encode('UTF-8') )
    per = MyEntityResolver()
    prsr = xml.sax.make_parser()
    prsr.setEntityResolver( per )
    prsr.parse( xmldoc )

----------------- to here -----------------------

Radovan Chytracek                CERN, IT/DB, LCG (SEAL in POOL)
mailto:Radovan.Chytracek at cern.ch Web: http://cern.ch/chytrace
phone: +41 22 76 74322           fax: +41 22 76 77155

More information about the XML-SIG mailing list