Issue 36233: xml ElementTree quotation marks of xml version string (original) (raw)

Created on 2019-03-08 10:08 by Photoniker, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ElementTree.py Photoniker,2019-03-08 10:08 ElementTree.py
Messages (8)
msg337463 - (view) Author: Johann Krauter (Photoniker) Date: 2019-03-08 10:08
I have the problem, that a xml file is save with the following xml declaration: instead of I would propose to change the line number 769 in the ElementTree.py to: write("\n" % ( declared_encoding,))
msg337489 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-03-08 15:15
Both quotes are valid. See https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd.
msg337520 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-03-08 18:01
+0 I support making this change, if only to keep the quoting convention consistent with how we quote attributes. Also, use of double quotes seems to be the norm. I made a brief informal survey of XML samples from multiple sources including DocBook, MS Excel, RSS feeds, the W3Schools examples, and various XML tutorials -- the only exception to double quotes was a NOAA weather feed. The XML spec itself shows a preference for double quotes in its examples.
msg337528 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2019-03-08 20:15
While I do understand the interest in a bit more visual consistency (and, lacking further input, I assume that this is the OP's "problem"), it really is at best a purely visual improvement with the potential to break code and/or tests out there. I'd rather not make that change. FWIW, lxml also uses single quotes in the XML declaration (originally following ElementTree), but double quotes by default for the rest, except for attributes that contain double quotes (but no single quotes). Any XML parser in the world is able to deal with that (since otherwise, it's not an XML parser). Nothing is broken here.
msg337654 - (view) Author: Johann Krauter (Photoniker) Date: 2019-03-11 10:10
The xml parser of OpenCV (3.4.5) in C++ is not able to load such xml file.
msg337671 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-03-11 14:43
Then report a bug to OpenCV. I do not think that changing quotation marks in the xml declaration will help much, since likely that parser has other flaws (for example what about using single quotes for attributes?). Changing quotation marks for sure will break many tests, in particularly our own tests. Needed a stronger reason to overcome this.
msg338596 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2019-03-22 09:32
I concur with Serhiy that the bug is in OpenCV (or its parser project), and that it is best solved there. Otherwise, we would create a dependency on a future/recent Python version for exporting XML to it.
msg338597 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2019-03-22 09:36
As a work-around, you can provide your own XML declaration (or not) and pass "xml_declaration=False" into ElementTree.write() to prevent it from adding one. UTF-8 encoded XML is ok without such a declaration.
History
Date User Action Args
2022-04-11 14:59:12 admin set github: 80414
2019-03-22 14:14:28 serhiy.storchaka set status: open -> closedresolution: not a bugstage: resolved
2019-03-22 09:36:38 scoder set messages: +
2019-03-22 09:32:13 scoder set messages: +
2019-03-11 14:43:52 serhiy.storchaka set messages: +
2019-03-11 10:10:54 Photoniker set messages: +
2019-03-08 20:15:42 scoder set messages: +
2019-03-08 18:01:23 rhettinger set nosy: + rhettingermessages: +
2019-03-08 15:15:07 serhiy.storchaka set messages: +
2019-03-08 12:52:34 xtreak set nosy: + scoder, eli.bendersky, serhiy.storchaka
2019-03-08 10:08:07 Photoniker create