Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Allowing & to appear in CDATA section #26

wants to merge 1 commit into from

1 participant

Jon Friskics
Jon Friskics

Right now, if an XML String has an & in a CDATA section running Indent XML doesn't do anything.

After removing CDATASTART, I'm looking in the CDATA section for any & and converting it to & before removing CDATAEND.

Then, when CDATASTART is added back in, I revert the & to & before adding CDATAEND back in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 2 deletions.
  1. +2 −2
@@ -88,12 +88,12 @@ def indent(self, s):
# convert to plain string without indents and spaces
s = re.compile(b'>\s+([^\s])', re.DOTALL).sub(b'>\g<1>', s)
# replace tags to convince minidom process cdata as text
- s = s.replace(b'<![CDATA[', b'%CDATAESTART%').replace(b']]>', b'%CDATAEEND%')
+ s = s.replace(b'<![CDATA[', b'%CDATAESTART%').replace(b'&', b'&amp;').replace(b']]>', b'%CDATAEEND%')
s = parseString(s).toprettyxml()
# remove line breaks
s = re.compile('>\n\s+([^<>\s].*?)\n\s+</', re.DOTALL).sub('>\g<1></', s)
# restore cdata
- s = s.replace('%CDATAESTART%', '<![CDATA[').replace('%CDATAEEND%', ']]>')
+ s = s.replace('%CDATAESTART%', '<![CDATA[').replace(b'&amp;', b'&').replace('%CDATAEEND%', ']]>')
# remove xml header
s = s.replace("<?xml version=\"1.0\" ?>", "").strip()
if xmlheader:
Something went wrong with that request. Please try again.