You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2016-08-30.18:21:18.624>created_at=<Date2016-08-30.17:18:25.805>labels= ['expert-XML', 'type-bug']
title='Apostrophe is not replace with ' ElementTree.tostring (also in Element.write)'updated_at=<Date2016-09-10.05:13:24.830>user='https://bugs.python.org/fruch'
Both on python2.7 and python3.4
>>> from xml.etree import cElementTree asET
>>> text ='<end>its > < & '</end>'
>>> root =ET.fromstring(text.encode('utf-8'))
>>> ET.tostring(root, method="xml")
<end>its > < & '</end>
I would expected to return the same as the input to be a complient XML 1.0
fromxml.etree.ElementTreeimport_escape_cdata ,_raise_serialization_errorfrommockimportpatchdef_escape_cdata(text):
# escape character datatry:
# it's worth avoiding do-nothing calls for strings that are# shorter than 500 character, or so. assume that's, by far,# the most common case in most applications.if"&"intext:
text=text.replace("&", "&")
if"<"intext:
text=text.replace("<", "<")
if">"intext:
text=text.replace(">", ">")
if"'"intext:
text=text.replace("'", "'")
returntextexcept (TypeError, AttributeError):
_raise_serialization_error(text)
fromxml.etreeimportcElementTreeasET
text = '<end>its > < & '</end>'
root = ET.fromstring(text.encode('utf-8'))
Definitely not a bug since this isn't required by the XML spec. As said in bpo-2647, you shouldn't rely on exact lexical characteristics of an XML byte stream, unless you request canonical serialisation (C14N).
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: