[issue24287] Let ElementTree prolog include comments and processing instructions

2019-04-27 Thread Stefan Behnel


Stefan Behnel  added the comment:

This is a duplicate of 9521, but it's difficult to say which ticket is better.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24287] Let ElementTree prolog include comments and processing instructions

2019-04-27 Thread Stefan Behnel


Change by Stefan Behnel :


--
superseder:  -> xml.etree.ElementTree skips processing instructions when parsing

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24287] Let ElementTree prolog include comments and processing instructions

2015-05-26 Thread Stefan Behnel

Stefan Behnel added the comment:

FTR, lxml's Element class has addnext() and addprevious() methods which are 
commonly used for this purpose. But ET can't adopt those due to its different 
tree model.

I second Martin's comment that ET.append() is a misleading name. It suggests 
adding stuff to the end, whereas things are actually being inserted before the 
root element here.

I do agree, however, that this is a helpful feature and that the ElementTree 
class is a good place to expose it. I propose to provide a prolog (that's the 
spec's spelling) property holding a list that users can fill and modify any way 
they wish. The serialiser would then validate that all content is proper XML 
prologue content, and would serialise it in order.

My guess is that lxml would eventually use a MutableSequence here that maps 
changes directly to the underlying tree (and would thus validate them during 
modification), but ET can be more lenient, just like it allows arbitrary 
objects in the text and tail properties which only the serialiser rejects.

Note that newlines can easily be generated on user side by setting the tail of 
a PI/Comment to \n. (The serialiser must also validate that the tail text is 
only allowed whitespace.)

For reference:

http://www.w3.org/TR/REC-xml/#sec-prolog-dtd

--
components: +XML

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24287
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24287] Let ElementTree prolog include comments and processing instructions

2015-05-25 Thread Raymond Hettinger

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.
/current_observation

--
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 rep...@bugs.python.org
http://bugs.python.org/issue24287
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24287] Let ElementTree prolog include comments and processing instructions

2015-05-25 Thread Martin Panter

Martin Panter added the comment:

The ElementTree class imitates or wraps many methods of the Element class. 
Since Element.append() and remove() already exist and act on children of the 
element, I think the new ElementTree methods should be named differently. Maybe 
something like prolog_append() and prolog_remove()? Or prologue_append() 
depending on your spelling preferences :P

Also, maybe the new write() calls should add newlines.

--
nosy: +vadmium

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24287
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com