[Python-Dev] c/ElementTree XML serialisation

And Clover and-dev at doxdesk.com
Wed May 9 00:15:43 CEST 2012


On 08/05/12 17:21, Alex Leach wrote:
 > The w3c SVG specification / recommendation
 > <http://www.w3.org/TR/SVG/script.html>  allows for<script>  and<style>
 > tags, recommending to wrap the text node in a<![CDATA[ … ]]>.

The spec uses a CDATA section in the example, for demonstration purposes 
only. It's not a recommendation.

CDATA sections are of use for hand-authoring readability, but don't help 
in machine-serialised documents. You don't get away from the need to 
encode out-of-band sequences (notably ]]> is still invalid) so it 
doesn't buy you any simplicity.

 > it's definitely a problem when generating SVG

No, not really. Neither XML nor SVG mandate use of CDATA sections here; 
a normal XML-encoded text node as produced by _serialize_xml is fine, 
and works with all XML processing tools.

HTML serialisation has custom rules (the two CDATA elements) because the 
HTML syntax is not XML. XML languages (including SVG and non-legacy 
served-as-XML XHTML) have no such special cases.

(There are other problems in ElementTree's serialiser that make the 
output unreflective of the infoset in certain cases, but not here.)

-- 
And Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/
gtalk:chat?jid=bobince at gmail.com


More information about the Python-Dev mailing list