[New-bugs-announce] [issue24287] Let ElementTree prolog include comments and processing instructions

Raymond Hettinger report at bugs.python.org
Tue May 26 02:54:10 CEST 2015

New submission from Raymond Hettinger:

Currently, ElementTree doesn't support comments and processing instructions in the prolog.  That is the typical place to put style-sheets and document type definitions.

It would be used like this:

    from xml.etree.ElementTree import ElementTree, Element, Comment, ProcessingInstruction

    r = Element('current_observation', version='1.0')
    r.text = 'Nothing to see here.  Move along.'
    t = ElementTree(r)
    t.append(ProcessingInstruction('xml-stylesheet', 'href="latest_ob.xsl" type="text/xsl"'))
    t.append(Comment('Published at: http://w1.weather.gov/xml/current_obs/KSJC.xml'))

That creates output like this:

    <?xml version='1.0' encoding='utf-8'?>
    <?xml-stylesheet href="latest_ob.xsl" type="text/xsl"?>
    <!--Published at: http://w1.weather.gov/xml/current_obs/KSJC.xml-->
    <current_observation version="1.0">
    Nothing to see here.  Move along.

files: xml_prolog.diff
keywords: patch
messages: 244069
nosy: eli.bendersky, rhettinger, scoder
priority: normal
severity: normal
status: open
title: Let ElementTree prolog include comments and processing instructions
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file39498/xml_prolog.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list