[XML-SIG] Setting the DOCTYPE in a new XML DOM

Douglas Bates bates@stat.wisc.edu
11 Jan 2002 17:30:59 -0600


System: Debian 3.0 (testing) GNU/Linux with the python2.2 and
  python2.2-xml packages installed.

||/ Name           Version        Description
+++-==============-==============-============================================
ii  python2.2      2.2-2          An interactive object-oriented scripting la
ii  python2.2-xml  0.6.6-7        XML tools for Python (2.2.x)

I have been unable to determine how to set the SYSTEM in the doctype
of a document read by the PyExpat reader.  I am rather new to this so
it is possible that I am doing something foolish.  I have mostly been
following demo's and examples as I haven't been able to track down a
lot of documentation.  A sample program is

#!/usr/bin/env python2.2

from xml.dom.ext.reader.PyExpat import Reader
from xml.dom.ext import PrettyPrint

if __name__ == "__main__":
    reader = Reader()
    doc = reader.fromUri("/tmp/foo1.xml")
    PrettyPrint(doc)

The file /tmp/foo1.xml begins

<?xml version="1.0"?>
<!DOCTYPE booklist SYSTEM "file:////home/deepayan/python/book.dtd">
<booklist>
  <book>

but the output file begins

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE booklist>
<booklist>
  <book>

Can anyone tell me what I do to maintain the SYSTEM designation?

Also, how do I set the SYSTEM designation when I create a new
document, say as in

    def __init__(self, dom = None):
        '''Initialize from an existing document object model
        or create a new DOM.
        '''
        if dom:
            self.doc = dom
            self.vol = dom.getElementsByTagName('volume')[0]
        else:
            from xml.dom.DOMImplementation import implementation
            self.doc = implementation.createDocument(None, None, None)
            self.vol = self.doc.createElement('volume')
            self.doc.appendChild(self.vol)