Problem with CDATAs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Collin VanDyck

    #1

    Problem with CDATAs

    I'm using Xalan's TransformerIden tityImpl class to provide a nice base
    framework upon which to write SAX transformers.

    However, using the identiy transform, I'm getting some weird output issues.

    My source xml looks like this:

    ....
    <script>
    <![CDATA[
    <!--
    some javascript here
    //-->
    ]]>
    </script>

    And I am getting something out that looks like this:

    <script type="text/javascript" language="JavaS cript"><![CDATA[
    ]]><![CDATA[
    <!--]]><![CDATA[
    function MM_swapImgResto re() { //v3.0]]><![CDATA[
    var i,x,a=document. MM_sr; for(i=0;a&&i<a. length&&(x=a[i])&&x.oSrc;i++ )
    x.src=x.oSrc;]]><![CDATA[
    }]]><![CDATA[
    ........ ad nauseum

    Of course, my first example left out the javascript, but it was javascript
    without any CDATA tags inside of it. The result is that my javascript has
    tons of CDATAs everywhere. How do I stop this? Is the source XML in
    violation of some rule? This example was created using a plain identity
    transform -- nothing should have been changed as I understand it.

    Also, my transformers are constructed using:

    setOutputProper ties(OutputProp erties.getDefau ltMethodPropert ies("xml"));

    I'd appreciate any help on this -- thanks!

    Collin



  • Derek Harmon

    #2
    Re: Problem with CDATAs

    "Collin VanDyck" <thehoppocket@y ahoo.com> wrote in message news:rcvZb.7436 73$9p3.141775@n ews.easynews.co m...[color=blue]
    > I'm using Xalan's TransformerIden tityImpl class to provide a nice base
    > framework upon which to write SAX transformers.
    >
    > However, using the identiy transform, I'm getting some weird output issues.[/color]

    So you have one <[CDATA[ ... ]]> section wrapping a <script> block, but
    Xalan is generating multiple CDataSections for every newline of the <script>
    block. It's inefficient, but not incorrect.

    <[CDATA[ some text ]]>

    is equivalent to ...

    <[CDATA[ some]]><[CDATA[ text]]>

    as far as it's information content goes. On the SAX end, you'll receive two
    consecutive CDATA sections in your LexicalHandler, but you're expected to
    handle it just like receiving adjoining characters within ContentHandler (which
    you will also likely be experiencing when this is happens.)

    What is the xml:space attribute on the source document? Perhaps a setting
    of "preserve" here might be a nudge of encouragement to Xalan not to create
    a CDATA section for each newline.

    You might also want to search/ask on the users mailing list of Xalan-J or
    Xalan-C, the archives of which are kept at:




    Derek Harmon


    Comment

    • Collin VanDyck

      #3
      Re: Problem with CDATAs

      > What is the xml:space attribute on the source document? Perhaps a setting[color=blue]
      > of "preserve" here might be a nudge of encouragement to Xalan not to[/color]
      create[color=blue]
      > a CDATA section for each newline.[/color]

      The xml:space attribute is undeterminate, as my parsing and transforming
      must be applied to a wide variety of input XML.
      [color=blue]
      >
      > You might also want to search/ask on the users mailing list of Xalan-J or
      > Xalan-C, the archives of which are kept at:
      >
      > http://marc.theaimsgroup.com/[/color]

      Thanks for the heads up, and for the reply.



      Comment

      Working...