CDATA in ouput

59 views
Skip to first unread message

Carl Meyer

unread,
Jan 19, 2012, 5:18:40 PM1/19/12
to PyKML discuss
I am trying to use some code generated by
write_python_script_for_kml_document, and the description section of
my placemarks is quoted with a CDATA to allow easier hand editing. I
don't understand how the KML factory methods work, but I tried putting
'<![CDATA[' in the text, but the < got converted to a &LT. Any
suggestions, other than drop the CDATA ?

Tyler Erickson

unread,
Jan 19, 2012, 6:36:03 PM1/19/12
to PyKML discuss
Coincidentally, I just pushed changes related to this a couple of
hours ago.

The underlying lxml library escapes out CDATA when constructing
elements (although it lets you parse XML and preserve CDATA... I am
not sure why it is not consistent). The approach I have taken to
address this issue is to postprocess the KML once you have converted
it to a string. I have added a utility method that does this
(pykml.util.format_as_cdata) and there are tests that illustrate its
usage (pykml.test.test_util.KmlUtilTestCase.test_convert_csv_to_kml).

http://code.google.com/p/pykml/source/browse/src/pykml/util.py
http://code.google.com/p/pykml/source/browse/src/pykml/test/test_util.py

At present this method is only available in the trunk of the
repository.

Hope that helps you out.

- Tyler

Carl Meyer

unread,
Feb 7, 2012, 6:57:21 AM2/7/12
to PyKML discuss
I will review this, but I have my program working without it. It would
only be important to me if I wanted to hand edit the kml after
generation. I wrote the program to avoid hand editing.

I did patch sources to make input handling of cdata consistent. I am
not reading kml's at this time, I will check the patch, and post about
it.

On Jan 19, 6:36 pm, Tyler Erickson <tylerick...@gmail.com> wrote:
> Coincidentally, I just pushed changes related to this a couple of
> hours ago.
>
> The underlying lxml library escapes out CDATA when constructing
> elements (although it lets you parse XML and preserve CDATA... I am
> not sure why it is not consistent).  The approach I have taken to
> address this issue is to postprocess the KML once you have converted
> it to a string.  I have added a utility method that does this
> (pykml.util.format_as_cdata) and there are tests that illustrate its
> usage (pykml.test.test_util.KmlUtilTestCase.test_convert_csv_to_kml).
>
> http://code.google.com/p/pykml/source/browse/src/pykml/util.pyhttp://code.google.com/p/pykml/source/browse/src/pykml/test/test_util.py
Reply all
Reply to author
Forward
0 new messages