Hi,

I searched the archives but was unable to locate any questions
and answers on this subject, so my apologies if this has been
covered before.

In one of the recent releases of Xerces-J, the XHTML serializer's
behaviour was changed to always escape <script> and <style>
elements' content using CDATA sections. While this is certainly
permissable in XHTML (and recommended if the character content of
the element contains problematic characters, see [1]), this
behaviour is not always warranted or welcome. It seems that it
should be an optional serialization behaviour, rather than
hardwired in, or perhaps made sensitive to the specific character
data content of the element to be serialized.

In revision $Revision: 1.26 $ $Date: 2004/02/16 05:24:55 $ of
org.apache.xml.serializer.HTMLSerializer, on lines 395-404, and
again on lines 623-632, there's an if statement that automatically
tags <style> and <script> elements to be escaped as CDATA sections.

     if ( tagName.equalsIgnoreCase( "SCRIPT" ) ||
           tagName.equalsIgnoreCase( "STYLE" ) ) {
          if ( _xhtml ) {
              // XHTML: Print contents as CDATA section
              state.doCData = true;
          } else {
              // HTML: Print contents unescaped
              state.unescaped = true;
          }
      }

If just prior to *actually* performing the CDATA escaping, in
characters(String) and characters(char[],int,int), the character
data content were checked for the presence of '<' and '&'
characters, then state.doCData could safely be set false.

Alternately, a boolean option could be provided to turn off the
default behaviour, though this latter suggestion does have the
downside of potentially creating invalid serializations.

Because these CDATA sections are actually causing problems for
my own project, I've had to disable the setting of state.doCData
and just avoid invalid characters in my script and style elements.
Obviously this is a less than adequate solution, and I'm just
wondering if others have run across this.

Thanks,

Murray

[1] http://www.w3.org/TR/xhtml1/#h-4.8
......................................................................
Murray Altheim                    http://kmi.open.ac.uk/people/murray/
Knowledge Media Institute
The Open University, Milton Keynes, Bucks, MK7 6AA, UK               .

  The North American Aerospace Defense Command had gone so far
  as to develop exercises to counter the threat [of flying jets
  into skyscrapers] and, according to a Defense Department memo-
  randum unearthed by the commission, planned a drill in April
  2001 that would have simulated a terrorist crash into the Pentagon.
  http://www.sfgate.com/cgi-bin/article.cgi?file=/c/a/2004/07/25/MNG6S7SR421.DTL


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to