[XML-SIG] entity handling

Chris Herborth chrish at cryptocard.com
Mon Jan 26 14:43:38 EST 2004

I'm currently creating DOMs from my documents thusly:

from xml.dom.ext.reader import Sax2
from FindEntities import FindEntities

reader = Sax2.Reader( validate = True )
reader.parser.setEntityResolver( FindEntities() )

def getDOM( filename, error_output = None ):
     """ Return the processed DOM for the given XML file.

     error_output - a string or file object; errors/warnings will be
                    written there... default is stderr.
     setErrorHandler( error_output )
     return reader.fromStream( file( filename ) )

This is working well and validating properly.

I want to be able to handle entities myself in my DOM application instead of 
having their data automatically converted to whatever text they have in the 
entity declaration.  Unfortunately, I haven't been able to figure out _how_ 
to do this, despite digging through the maze of twisty passages (PyXML 
0.8.3) for a few hours.

I've tried adding this bits:

class MyHandler( Sax2.XmlDomGenerator ):
     def __init__( self, keepAllWs=0, implementation=implementation ):
         Sax2.XmlDomGenerator.__init__( self, keepAllWs, implementation )

     def skippedEntity( self, name ):
         """ Found an entity, preserve it...
         print "===> &%s;" % ( name, )
             self._ownerDoc.createEntityReference( name ) )

and using this to create the reader:

reader = Sax2.Reader( validate = True, saxHandlerClass = MyHandler )
reader.parser.setFeature( xml.sax.handler.feature_external_ges, 0 )

This gives me a "feature not supported" exception at the setFeature() call.

Is having entities in the DOM contrary to "proper" DOM application design or 
something?  To me, this seems like something that should be reasonably easy 
to do...

Any clues greatly appreciated!

Chris Herborth                                     chrish at cryptocard.com
Documentation Overlord, CRYPTOCard Corp.      http://www.cryptocard.com/
Never send a monster to do the work of an evil scientist.

More information about the XML-SIG mailing list