You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by "Liu, Richard" <Ri...@boeing.com> on 2005/03/17 22:10:10 UTC

A Question of CDADA handling in SerializeNodeSet example

Hi, 

  I am using Xalan-1.6.  I have a question about CDATA handling in one
of your example, "SerializeNodeSet".

  In the example, you have a foo.xml.

  I modify the original foo.xml to the following (simply adding a CDATA
section):

<?xml version="1.0"?>
<doc>

<![CDATA[
this is the cdata test section
]]>

  <name first="David" last="Marston">Mr. Marston</name>
  <name first="David" last="Bertoni">Mr. Bertoni</name>
  <name first="Donald" last="Leslie">Mr. Leslie</name>
  <name first="Emily" last="Farmer">Ms. Farmer</name>
  <name first="Myriam" last="Midy">Ms. Midy</name>
  <name first="Paul" last="Dick">Mr. Dick</name>
  <name first="Scott" last="Boag">Mr. Boag</name>
  <name first="Shane" last="Curcuru">Mr. Curcuru</name>
  <name first="Joseph" last="Kesselman">Mr. Kesselman</name>
  <name first="Stephen" last="Auriemma">Mr. Auriemma</name>
</doc>

When I run the program by typing "SerializeNodeSet ./foo.xml / doc", I
got the following result:

<doc>

this is the cdata test section

  <name last="Marston" first="David">Mr. Marston</name>
  <name last="Bertoni" first="David">Mr. Bertoni</name>
  <name last="Leslie" first="Donald">Mr. Leslie</name>
  <name last="Farmer" first="Emily">Ms. Farmer</name>
  <name last="Midy" first="Myriam">Ms. Midy</name>
  <name last="Dick" first="Paul">Mr. Dick</name>
  <name last="Boag" first="Scott">Mr. Boag</name>
  <name last="Curcuru" first="Shane">Mr. Curcuru</name>
  <name last="Kesselman" first="Joseph">Mr. Kesselman</name>
  <name last="Auriemma" first="Stephen">Mr. Auriemma</name>
</doc>




The "<![CDATA[" and "]]>" symbol simply disappeared in the output.  What
I want is that these CDATA symbols still exists after running the
program. 

 
I have tried the function "theFormatter.setEscapeCData (true) or
theFormatter.setEscapeCData (false)", it does not help at all.

Could you let me know how can I solve this problem?



Thanks

Richard Liu
Software Engineer at Boeing






Re: A Question of CDADA handling in SerializeNodeSet example

Posted by da...@us.ibm.com.
> I am using Xalan-1.6.  I have a question about CDATA handling
> in one of your example, "SerializeNodeSet".
> 
>   In the example, you have a foo.xml.

...

> When I run the program by typing "SerializeNodeSet ./foo.xml / doc",
> I got the following result:
> 
> <doc>
> 
> this is the cdata test section
> 
>   <name last="Marston" first="David">Mr. Marston</name>

...

> The "<![CDATA[" and "]]>" symbol simply disappeared in the output.
> What I want is that these CDATA symbols still exists after running
> the program. 

CDATA sections are not preserved in the Infoset, or in the XPath data 
model, so they are lost after parsing the source document.

> Could you let me know how can I solve this problem?

FormatterListener::cdata() will generate a CDATA section with the supplied 
data.  However, you will have to modify the class FormatterTreeWalker to 
call the cdata() member function for the text nodes you want serialized in 
CDATA sections.

Relying on the preservation of CDATA sections is generally a bad idea, 
because they are considered a lexical artifact of the input XML document, 
rather than a part of the document's data.

Dave