[XML-SIG] Expanding external entities

Alexandre Fayolle Alexandre.Fayolle@logilab.fr
Mon, 27 Aug 2001 17:40:12 +0200 (CEST)


On Mon, 27 Aug 2001, Nicolas Chauvat wrote:

> Hi List,
> 
> At the moment I'm using this piece of code :
> 
> def parse_file(filepath) :
>     from xml.sax.saxexts import make_parser
>     p = make_parser()
>     dh = MyParserHandler()
>     p.setDocumentHandler(dh)
>     p.parseFile(filepath)
>     return dh.myObject
> 
> which does not deal with entities defined like this :
> 
> <?xml version="1.0" encoding="iso-8859-1"?>
> <!DOCTYPE rootelement SYSTEM "MyOwn.dtd" [
> 	<!ENTITY tobeincluded.xml SYSTEM "tobeincluded.xml">
> ]>
> <rootelement>&tobeincluded;</rootelement>

First thing is, you're using SAX 1.0 interfaces which are deprecated. You
should use 

from xml.sax.sax2exts import make_parser

Maybe this alone will solve your problem, I'm not sure.

If it doesn't work, you could try using a validating parser. I'm pretty
sure xmlproc deals with external entities correctly.

from xml.sax.sax2exts import XMLValParserFactory
p = XMLValParserFactory.make_parser()

Cheers,

Alexandre Fayolle
-- 
LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org
Narval, the first software agent available as free software (GPL).