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.

Author vsurjaninov
Recipients vsurjaninov
Date 2019-03-23.15:38:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
If we are writing xml with CDATA section and leaving non-empty indentation and new-line parameters, a parent node of the section will contain useless indentation, that will be parsed as a text.

>>>doc = minidom.Document()
>>>root = doc.createElement('root')
>>>node = doc.createElement('node')
>>>data = doc.createCDATASection('</data>')
>>>print(doc.toprettyxml(indent=‘  ‘ * 4)
<?xml version="1.0" ?>
<![CDATA[</data>]]>    </node>

If we try to parse this output doc, we won’t get CDATA value correctly.

Following code returns a string that contains only indentation characters:
>>>doc = minidom.parseString(xml_text)

Returns a string with CDATA value and indentation characters:

But we have a workaround:
>>>data.nodeType = data.TEXT_NODE
>>>print(doc.toprettyxml(indent=‘  ‘ * 4)
<?xml version="1.0" ?>

It will be parsed correctly:

But I think it will be better if we fix the writing function, which would set this as default behavior.
Date User Action Args
2019-03-23 15:38:49vsurjaninovsetrecipients: + vsurjaninov
2019-03-23 15:38:49vsurjaninovsetmessageid: <>
2019-03-23 15:38:49vsurjaninovlinkissue36407 messages
2019-03-23 15:38:48vsurjaninovcreate