[XML-SIG] SAX and DTDs

Alin Dobre alin at gentoo.org
Sat Aug 6 19:23:07 CEST 2005


-----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-----


More information about the XML-SIG mailing list