[XML-SIG] SAX with DTD

Lars Marius Garshol larsga@garshol.priv.no
13 Jul 2001 11:30:42 +0200


* Hung Jung Lu
| 
| (2) I have a DTD that specifies default attributes (via #FIXED) of
| an XML document. Is there some parser (DOM preferred, SAX ok) in
| Python that can take into account the attributes specified in DTD?

xmlproc does this, and there is a SAX driver for it, so that you can
access it as a SAX parser. The DOM implementations use SAX to build
their DOM trees, so you can use xmlproc to build your DOMs.

[larsga@pc36 project]$ python2.1
Python 2.1 (#1, May  5 2001, 06:49:59) 
[GCC 2.95.1 19990816/Linux (release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> from xml.dom.ext.reader.Sax2 import Reader
>>> r = Reader(1)
>>> doc = r.fromStream(open("engine-plan.xml"))
>>> doc
<XML Document at 836d55c>

The 1 argument to Reader tells it to use a validating parser, so it
will do much the same as Jürgen's example, except with the DOM rather
than SAX. It uses xmlproc at the moment, because that's the only
validating parser we have.

--Lars M.