[XML-SIG] SAX with DTD

Hung Jung Lu hungjunglu@yahoo.com
Fri, 13 Jul 2001 07:12:37 -0700 (PDT)


Cool. It works! Yours is probably the shortest way of
attaching attributes from DTD to XML. Result can be
seen by

from xml.dom.ext import PrettyPrint
PrettyPrint(doc)

I did try xmlproc directly, too. More coding for the
handlers, but I guess it's good if one wants to
convert XML directly into Python objects instead of
going through DOM.

Thanks everyone!

Hung Jung

--- Lars Marius Garshol <larsga@garshol.priv.no>
wrote:
> 
> * 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.
> 
> 
> _______________________________________________
> XML-SIG maillist  -  XML-SIG@python.org
> http://mail.python.org/mailman/listinfo/xml-sig


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/