This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: xml ElementTree quotation marks of xml version string
Type: behavior Stage: resolved
Components: XML Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Photoniker, eli.bendersky, rhettinger, scoder, serhiy.storchaka
Priority: normal Keywords:

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: 
<?xml version='1.0' encoding='utf-8'?> 
instead of 
<?xml version="1.0" encoding="utf-8"?>

I would propose to change the line number 769 in the ElementTree.py to: 
write("<?xml version=\"1.0\" encoding=\"%s\"?>\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:12adminsetgithub: 80414
2019-03-22 14:14:28serhiy.storchakasetstatus: open -> closed
resolution: not a bug
stage: resolved
2019-03-22 09:36:38scodersetmessages: + msg338597
2019-03-22 09:32:13scodersetmessages: + msg338596
2019-03-11 14:43:52serhiy.storchakasetmessages: + msg337671
2019-03-11 10:10:54Photonikersetmessages: + msg337654
2019-03-08 20:15:42scodersetmessages: + msg337528
2019-03-08 18:01:23rhettingersetnosy: + rhettinger
messages: + msg337520
2019-03-08 15:15:07serhiy.storchakasetmessages: + msg337489
2019-03-08 12:52:34xtreaksetnosy: + scoder, eli.bendersky, serhiy.storchaka
2019-03-08 10:08:07Photonikercreate