XML.com: XML From the Inside Out

XML.comWebServices.XML.comO'Reilly Networkoreilly.com
  Articles | Weblogs | Newsletter | Safari Bookshelf
advertisement

Article:
 XSLT, Browsers, and JavaScript
Subject: Scripts need CDATA too
Date: 2003-03-16 05:20:41
From: drefty mcphooter
Response to: Scripts need CDATA too

Your remark "I find that nearly all uses of CDATA are kludges..." is probably consistent with someone who has strong knowledge, affinity and preference for XSLT, but perhaps it is also good to remember that not everyone shares the same affinity. Here are some reasons why CDATA might not be a "kludge"


1. What if you have a tool that 'autogenerates' both XSLT *and* the enclosed JavaScript in <script></script> tags? You cannot rely on a simple 'search and replace' to insert entity references, because it will produce unpredictable results. (a common scenario in computer programming that I call 'The delimiter collision problem').


2. You yourself experienced the problem where you wanted to show < but the browser interpolated the entity reference when you didnt intend it to ('The delimiter context problem').


3. What if the insertion of entity references renders the JavaScript code unreadable (either by a human being, or other agent, such as a JavaScript debugger or IDE)? Many people dislike XSLT when it is written in such a way that it is difficult to tell what the transformation will look like just by looking at the XSLT itself. ('The template round-tripping problem' and 'The template transparency problem').


I, for one, am glad that XSLT has a facility such as CDATA, because it's reasonable to assume that 'quick and dirty' does not always mean 'kludge'. One person's 'kludge' is another person's preference for getting work done faster.


And afterall, you could say that *all* computer software is a 'kludge' for something that a person would rather be able to do without having to use a computer at all.


NOTE: buzzwords like "kludge" and "elegant" get tossed around all the time with no definition. Here, I define "kludge" as: "A use of a tool in a manner that is dramatically inconsistent with the intentions and goals of the people who designed the tool, the end result being an increase in the tedium and difficulty of maintenance." Also implied with the term 'kludge' is the principle that the perpetrator is not knowledgable about the subtleties of the tool itself.


Previous Message Previous Message Move up to Parent Message Up Next Message No Next Message


Titles Only Titles Only Newest First
  • Scripts need CDATA too
    2003-03-17 19:17:47 Bob DuCharme [Reply]

    I have seen CDATA used to solve problems that couldn't be solved better any other way--for example, sending XML that includes a DOCTYPE declaration as part of a SOAP message.


    I have seen CDATA used in many different contexts, and the ones that qualify as solving problems that couldn't be solved any other way were a tiny minority. That's why I said that *nearly* all uses of CDATA are kludges.


    Bob


Sponsored By:


Contact Us | Our Mission | Privacy Policy | Advertise With Us | | Submissions Guidelines
Copyright © 2008 O'Reilly Media, Inc. | (707) 827-7000 / (800) 998-9938