Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
There's more than one way to do things
 
PerlMonks  

Re: CDATA in an XML file for parsing.

by dimar (Curate)
on Jan 02, 2006 at 18:29 UTC ( [id://520472]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to CDATA in an XML file for parsing.

You will do well to consider the admonition made earlier by Aristotle. If you find yourself tempted to reach for the 'CDATA' or 'entity-escaping' key-combination in your text-editor or IDE, do not do it unless and until you have given serious consideration to alternatives.

Such as:
  • apply base64 encode and base64 decode
  • supply a link to the external (non-well-formed) resource

If you have control over the generation of the content, there is no excuse why you should not at least *consider* the alternatives.

If you do *not* have control over the entire content, it is all the more reason to consider the woes of naively tossing around CDATA and escaping.

  • What if the content itself contains a 'CDATA' section that is intended to be displayed as an example of how to make a 'CDATA' section?
  • What if the content contains (ampersand)nbsp; that is intended to demonstrate the symbol used to represent blank space (and not intended to be rendered as an actual blank space)?
  • What if the content contains typos that just coincidentally happen to look like codes in your escaping mechanism?

There are many many reasons why escaping and CDATA is often a bad way to go. This badness is exactly why perl has 'quotelike operators' and why MIME has 'multipart boundary delimiters'. XML has neither of these, so often people resort to CDATA and escaping, even when that is *not* the best, (or even a good) way to go.

=oQDlNWYsBHI5JXZ2VGIulGIlJXYgQkUPxEIlhGdgY2bgMXZ5VGIlhGV

Replies are listed 'Best First'.
Re^2: CDATA in an XML file for parsing.
by Aristotle (Chancellor) on Jan 03, 2006 at 07:16 UTC

    Note that these “What if” questions all have unambiguous answers; any ambiguities result from buggy software, not from the XML spec. The reason for avoiding escaped markup within CDATA is not that it causes ambiguities in the data, but the many difficulties embedded markup causes for processing and that the well-formedness guarantee you get by using XML is thrown out of the window.

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://520472]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.