gh-81055: Support CDATA sections in xml.etree.ElementTree - #156923
Draft
serhiy-storchaka wants to merge 1 commit into
Draft
gh-81055: Support CDATA sections in xml.etree.ElementTree#156923serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
CDATA is a str subclass for character data which is serialized as a CDATA section. It can be used as the text or the tail of an element. The content of a CDATA section is parsed as ordinary character data by default. If insert_cdata is true, TreeBuilder adds it to the tree as a CDATA string: as the text or the tail of an element if it is not set yet, and otherwise in a new element with the tag None. A section does not share the place with what follows it, so it is moved to such an element if character data or another section follows it. The C implementation supports this too: pyexpat exposes XML_SetCdataSectionHandler in its capsule, and _set_factories takes the CDATA type as the third argument.
Documentation build overview
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An alternative to #156742:
CDATAis astrsubclass for character data which is serialized as a CDATA section, instead of a factory of special elements. It can be used as the text or the tail of an element:The content of a CDATA section is parsed as ordinary character data by default. If insert_cdata is true,
TreeBuilderadds it to the tree as aCDATAstring: as the text or the tail of an element if it is not set yet, and otherwise in a new element with the tagNone. A section does not share the place with what follows it, so it is moved to such an element if character data or another section follows it.Since the content is character data, it is a part of the inner text returned by
itertext()and by the"text"serialization method, without any change inElement.pyexpat exposes
XML_SetCdataSectionHandlerin its capsule, and_set_factories()takes theCDATAtype as the third argument, so the C implementation supports this too.