[Python-Dev] c/ElementTree XML serialisation

Alex Leach albl500 at york.ac.uk
Wed May 9 01:41:25 CEST 2012


On Tuesday 08 May 2012 23:15:43 And Clover wrote:
| 
| 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 not simplicity I'm looking for but functionality. I did initially make a 
true XML generator (no javascript or CSS intended or included), but including 
a small ecmascript rather than 500,000 separate x and y co-ordinates made the 
SVG about 28MB simpler, so I'm ahead already. The current XML generator can't 
be used to write javascript stored within any Element because it forcefully 
substitutes >, < and & for their HTML counterparts.

| 
|  > 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.

Maybe the script block doesn't require CDATA wrappers, but style blocks 
without them don't work, at least in firefox. Perhaps even worse, vim 
highlighting breaks too!

Quoting: http://www.w3.org/TR/SVG/styling.html#StylingWithCSS

"""Note how the CSS style sheet is placed within a CDATA construct (i.e., <!
[CDATA[ ... ]]>). Placing internal CSS style sheets within CDATA blocks is 
sometimes necessary since CSS style sheets can include characters, such as 
">", which conflict with XML parsers. Even if a given style sheet does not use 
characters that conflict with XML parsing, it is highly recommended that 
internal style sheets be placed inside CDATA blocks."""

| 
| 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.

True. I might not need the CDATA tag to wrap the javascript then, but I still 
need < and > symbols. I have no idea how to write a loop in javascript without 
one.

| 
| (There are other problems in ElementTree's serialiser that make the
| output unreflective of the infoset in certain cases, but not here.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120509/4989a58e/attachment.html>


More information about the Python-Dev mailing list