Re: SAX and DTDs

Alin Dobre <[email protected]>
Newsgroups gmane.comp.python.xml
Organization Gentoo Foundation / Gentoo.RO Community
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alin Dobre wrote:
>   Hey list,
>
> I have a python script that does a simple parsing of a XML document
> using SAX. The problem is that I cannot get to validate the XML using an
> external DTD file.
>
> ------------
> #!/bin/env python
> import sys
> from xml.sax import saxlib, saxexts
> class mySaxDH(saxlib.HandlerBase):
>   def startDocument(self):
>     print 'Document start'
> handler = manSaxDH(sys.stdout)
> parser = saxexts.make_parser()
> parser.setDocumentHandler(handler)
> inFile = file(sys.argv[1], 'r')
> parser.parseFile(inFile)
> inFile.close()
> ------------
> <?xml version="1.0"?>
> <!DOCTYPE man SYSTEM "my.dtd">
> <tag>data</tag>
> ------------
>
> For the examples shown above, I want to validate the xml stream against
> the my.dtd file. Any idea how to do this using SAX?
>
> Thanks,
> Alin.

Solved. I have used sax.sax2exts.XMLValParserFactory and now it
validates the XML against the DTD file.

PS: I've already seen that Uche Ogbuji gave me the same solution. Thanks.
- --
Alin DOBRE
Romanian Lead Translator
Gentoo Documentation Project: http://www.gentoo.org/doc/en/
Gentoo.RO Community:          http://www.gentoo.ro/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFC9PH7mG51ym6Hu9gRAv0KAKDv1ManMguTjiJRu/n3zPrwrcFHIgCgmQ8q
K/nWS4JiSaArqi59DVkEkRE=
=sFNa
-----END PGP SIGNATURE-----
_______________________________________________
XML-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/xml-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.