[XML-SIG] make_parser

Uche Ogbuji uche.ogbuji at fourthought.com
Thu Sep 9 14:05:04 CEST 2004


On Tue, 2004-09-07 at 04:59, Ajay wrote:
> hi!
> 
> in my code, i am giving make_parser the name of the parser i'd like to use
> the code is below
> 
> parser = make_parser(['xmlproc'])
> parser.setFeature(feature_namespaces, 0)
> dh = FindIssue()
> 
> # Tell the parser to use our handler
> parser.setContentHandler(dh)
> # Parse the input
> f = open('\um\proxy\policy-eg1.xml')
> str = f.read()
> f.close()
> print "file read"
> parser.parseString(str)
> 
> this throws an error saying ExpatParser instance has no attribute
> 'parseString'
> 
> what am i doing wrong? i thought i was using xmlproc

You thought wrongly, and it's easy to check:

>>> from xml.sax import make_parser
>>> print make_parser(['xmlproc'])
<xml.sax.expatreader.ExpatParser instance at 0x553e56ac>

clearly expat

>>> print make_parser(['xml.sax.drivers.drv_xmlproc'])
<xml.sax.drivers.drv_xmlproc.SAX_XPParser instance at 0x553e590c>

clearly xmlproc

make_parser falls back to its defaults if none of the drivers you list
can be imported.


-- 
Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
Meet me at XMLOpen Sept 21-23 2004, Cambridge, UK.  http://xmlopen.org

A hands-on introduction to ISO Schematron - http://www-106.ibm.com/developerworks/edu/x-dw-xschematron-i.html
Practical (Python) SAX Notes - http://www.xml.com/pub/a/2004/08/11/py-xml.html
XML circles the globe - http://www.javareport.com/article.asp?id=9797
Element structures for names and addresses - http://www.ibm.com/developerworks/xml/library/x-elemdes.html
Commentary on "Objects. Encapsulation. XML?" - http://www.adtmag.com/article.asp?id=9090
Harold's Effective XML - http://www.ibm.com/developerworks/xml/library/x-think25.html
A survey of XML standards - http://www-106.ibm.com/developerworks/xml/library/x-stand4/



More information about the XML-SIG mailing list