[XML-SIG] preserving doctype declaration with xml.dom?

Jed Parsons jedp@ilm.com
Fri, 9 Aug 2002 11:37:29 -0700 (PDT)


I'm losing <!DOCTYPE> information when going from text to dom and back 
to text again.  I'm using PyXML-0.7.1 and 4Suite-0.12.0a2.

If I have a document like this (the css thing is for an editor):

  <?xml version='1.0' encoding='UTF-8'?>
  <!DOCTYPE mine SYSTEM "/path/to/mine.dtd">
  <?xml-stylesheet type="text/css" href="file:/path/to/my.css"?>
  <document>
   ... blah ...
  </document>

And I do this:

    # convert xml file to dom
    reader = xml.dom.ext.reader.PyExpat.Reader()
    input  = open("file.xml")
    dom    = reader.fromString(input.read())
    
    # ... add some attributes to some elements here, only
    # touching things in the dom.documentElement ...
    
    # convert back to text and save
    string = StringIO.StringIO()
    xml.dom.ext.Print(dom, string)
    # and write string.getValue() to a file...

When I look at my new file, the doctype declaration just says

   <!DOCTYPE mine>

Am I doing something wrong?  Thanks in advance for any help,

Jed   
  
-- 
Jed Parsons       Industrial Light + Magic  (415) 448-2974 
	     
grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and
grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6))))}},(split(//,
"++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0.  What!?")));