[XML-SIG] Preserving XML and DocType declaration attributes using DOM

Dinu Gherman gherman@darwin.in-berlin.de
Tue, 19 Mar 2002 11:47:36 +0100 (CET)


Hi, I have something like the DOM code below, where I don't succedd in
getting at the doctype attributes. I'm trying to read an XML file with 
DOM, manipulate it and save it to a new file... The PrettyPrint function
seems not to preserve the attributes of the XML and doctype declarations. 

Is there some other canonical way of doing this, maybe? Or is it an
issue with the Python 2.2 and PyXML 0.7 I'm using?

Thanks,

Dinu



    """<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
    <!DOCTYPE document SYSTEM "doc.dtd">

    ...
    """

    from xml.dom.ext.reader.Sax2 import FromXmlStream
    from xml.dom.ext import PrettyPrint

    path = ... # see snippet above
    doc = FromXmlStream(path)
    dt = doc.doctype

    print dt.name, dt.systemId, dt.publicId 
    # gives: document  None
    print map(type, (dt.name, dt.systemId, dt.publicId)) 
    # gives: [<type 'unicode'>, <type 'str'>, <type 'NoneType'>]

    PrettyPrint(doc)
    # gives:
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE document>
    ...