tylere / pykml

pyKML is a Python package for creating, parsing, manipulating, and validating KML documents.
BSD 3-Clause "New" or "Revised" License
13 stars 9 forks source link

Parsing without schema validatation doesn't preserve CDATA sections #31

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Parse some KML with <![CDATA[]]> without using a schema: parser.parse(f, 
schema=None)

When writing the document back out to file, CDATA sections are lost, and all 
characters are converted to HTML entities.

This doesn't happen when parsing with schema validation.

Can be rectified by modifying line 55+ of parse.py to this:

# without validation
   parser = objectify.makeparser(strip_cdata=False)
   return objectify.parse(fileobject, parser=parser)

Original issue reported on code.google.com by alchem...@google.com on 13 Oct 2011 at 11:21

GoogleCodeExporter commented 8 years ago
Modified existing test 
(GeneratePythonScriptTestCase.test_write_python_script_for_kml_document) to 
test for this issue.  Test passed with the suggested modification.

changeset:   58:0e1a5a41bbb1
tag:         tip
user:        taericks@precisionm6500b
date:        Tue Nov 01 14:49:27 2011 -0700
summary:     parsing without a schema now preserves a CDATA section (Issue 31)

Original comment by tylerick...@gmail.com on 1 Nov 2011 at 9:52

GoogleCodeExporter commented 8 years ago
I would suggest that fromstring needs a similar modification, at line 41:

        parser = objectify.makeparser( strip_cdata=False)
        return objectify.fromstring( text, parser=parser)

to make string behaviour consistent with fileobject  

Original comment by hcme...@gmail.com on 4 Jan 2012 at 2:44