C
Cees Wesseling
Hi,
it seems that xmlproc, the default Validating parser, in my setup does
not call back to setDocumentLocator. Is there anyway to get a locator
in my handler?
Below you find an example and its output.
Regards, Cees
# base imports
from xml.sax.handler import ContentHandler
from xml.sax.handler import EntityResolver
import xml.sax
import xml.sax.sax2exts
class BaseHandler(ContentHandler):
def setDocumentLocator(self,locator):
print "setDocumentLocator called"
self.d_locator=locator
def startElement(self, name, attr):
print "startElement", name
open('e.dtd','w').write('<!ELEMENT E EMPTY>')
open('e.xml','w').write(
"""<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE E SYSTEM "e.dtd"><E/>""")
vp = xml.sax.sax2exts.XMLValParserFactory.make_parser()
print "vp type", vp.__class__
vph = BaseHandler()
vp.setContentHandler(vph)
vp.parse("e.xml")
np = xml.sax.make_parser()
print "np type", np.__class__
nph = BaseHandler()
np.setContentHandler(nph)
np.parse("e.xml")
OUTPUT:
vp type xml.sax.drivers2.drv_xmlproc.XmlprocDriver
startElement E
np type xml.sax.expatreader.ExpatParser
setDocumentLocator called
startElement E
it seems that xmlproc, the default Validating parser, in my setup does
not call back to setDocumentLocator. Is there anyway to get a locator
in my handler?
Below you find an example and its output.
Regards, Cees
# base imports
from xml.sax.handler import ContentHandler
from xml.sax.handler import EntityResolver
import xml.sax
import xml.sax.sax2exts
class BaseHandler(ContentHandler):
def setDocumentLocator(self,locator):
print "setDocumentLocator called"
self.d_locator=locator
def startElement(self, name, attr):
print "startElement", name
open('e.dtd','w').write('<!ELEMENT E EMPTY>')
open('e.xml','w').write(
"""<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE E SYSTEM "e.dtd"><E/>""")
vp = xml.sax.sax2exts.XMLValParserFactory.make_parser()
print "vp type", vp.__class__
vph = BaseHandler()
vp.setContentHandler(vph)
vp.parse("e.xml")
np = xml.sax.make_parser()
print "np type", np.__class__
nph = BaseHandler()
np.setContentHandler(nph)
np.parse("e.xml")
OUTPUT:
vp type xml.sax.drivers2.drv_xmlproc.XmlprocDriver
startElement E
np type xml.sax.expatreader.ExpatParser
setDocumentLocator called
startElement E