[Python-Dev] Encoding of code in XML

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Wed, 19 Apr 2000 19:50:17 +0200


David Ascher wrote:
> > What is wrong with encoding ]]> in the XML way by using an extra
> > CDATA.  In other words split up the CDATA section into two in the
> > middle of the ]]> sequence:
> >
> > import string
> > def encode_cdata(str):
> >     return '<![CDATA[' + \
> >    string.join(string.split(str, ']]>'), ']]]]><![CDATA[>')) + \
> >    ']]>'
>=20
> If I understand what you're proposing, you're splitting a single bit =
of
> Python code into N XML elements.

nope.  CDATA sections are used to encode data, they're not
elements:

    XML 1.0, section 2.7:

    CDATA sections may occur anywhere character data may
    occur; they are used to escape blocks of text containing
    characters which would otherwise be recognized as mark-
    up.

you can put each data character in its own CDATA section,
if you like.  if the parser cannot handle that, it's broken.

(if you've used xmllib, think handle_data, not start_cdata).

</F>