  | |  | Adjacent CDATA node problems | Adjacent CDATA node problems 2003-03-19 - By Mike McLean
I'm currently experiencing much grief over CDATA nodes not transforming correctly. The exact problem is that the processor outputs adjacent CDATA nodes for no apparent reason. I've looked at the text through a hex editor and there are no strange characters causing this to happen.
The problem I'm having seems to be outlined here: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10726
Here's an example of what's happening:
A document containing this:
<element> <news> High Estrogen/Progestin Levels May Reduce Asthma Severity </news> </element>
Gets transformed to this:
<element> <news> <![CDATA[High Estrogen/Progestin Levels May Redu]]><CDATA[ce Asthma Severity]]> </news> </element>
Using a stylesheet which specifies that the news element should be cdata: <xsl:output method="xml" encoding="ISO-8859-1" cdata-section-elements="headline news" media-type="text/xml" standalone="no" />
- I'm currently using Xalan 2.4.1 (unpatched). - This is a servlet using Tomcat 4.12 - My web-inf/lib contains (xml related) jaxb-api.jar, jaxb-libs.jar, jaxb-ri.jar, jaxen-full.jar, xalan.jar, xerces.jar and xercesImpl.jar
Here's some sample code on how I'm doing it all:
JAXBSource source = null; JAXBContext jc = JAXBContext.newInstance("blabla"); ObjectFactory factory = new ObjectFactory(); List objects = null; Marshaller marshaller = jc.createMarshaller(); ....
source = new JAXBSource(jc, dgn); marshaller.marshal(dgn, System.out); System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl"); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(new StreamSource("mysheet.xslt")); t.transform(source, new StreamResult(transformedOut));
The marshal statement sends a string of xml back without any CDATA nodes. I rely on the Transform to do that.
I would like to upgrade to 2.5.1d but can't because I keep getting this error as soon as I replace the jar: The output format must have a '{http://xml.apache.org/xslt}content-handler' property
So I'm stuck with 2.4.1 unless I resolve this other problem.
Thanks for any input.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"> <META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6249.1"> <TITLE>Adjacent CDATA node problems</TITLE> </HEAD> <BODY> <!-- Converted from text/rtf format -->
<P><FONT COLOR="#800000" SIZE=2 FACE="Verdana">I'm currently experiencing much grief over CDATA nodes not transforming correctly. The exact problem is that the processor outputs adjacent CDATA nodes for no apparent reason. I've looked at the text through a hex editor and there are no strange characters causing this to happen. </FONT></P>
<P><FONT COLOR="#800000" SIZE=2 FACE="Verdana">The problem I'm having seems to be outlined here: </FONT><A HREF="http://nagoya.apache.org/bugzilla/show_bug .cgi?id=10726"><U></U><U><FONT COLOR="#0000FF" SIZE=2 FACE="Verdana">http:/ /nagoya.apache.org/bugzilla/show_bug.cgi?id=10726</FONT></U></A><FONT COLOR=" #800000" SIZE=2 FACE="Verdana"> </FONT> </P>
<P><FONT COLOR="#800000" SIZE=2 FACE="Verdana">Here's an example of what's happening:</FONT> </P>
<P><FONT COLOR="#800000" SIZE=2 FACE="Verdana">A document containing this:< /FONT> </P>
<P><FONT COLOR="#800000" SIZE=2 FACE="Verdana"><element></FONT>
<BR><FONT COLOR="#800000" SIZE=2 FACE="Verdana"> <news></FONT>
<BR> <FONT COLOR="#800000" SIZE=2 FACE="Verdana">High Estrogen/Progestin Levels May Reduce Asthma Severity</FONT>
<BR><FONT COLOR="#800000" SIZE=2 FACE="Verdana"> </news>< /FONT>
<BR><FONT COLOR="#800000" SIZE=2 FACE="Verdana"></element></FONT> </P>
<P><FONT COLOR="#800000" SIZE=2 FACE="Verdana">Gets transformed to this:</FONT> </P>
<P><FONT COLOR="#800000" SIZE=2 FACE="Verdana"><element></FONT>
<BR><FONT COLOR="#800000" SIZE=2 FACE="Verdana"> <news></FONT>
<BR> <FONT COLOR="#800000" SIZE=2 FACE="Verdana"><![CDATA[High Estrogen/Progestin Levels May Redu]]>< ;CDATA[ce Asthma Severity]]></FONT>
<BR><FONT COLOR="#800000" SIZE=2 FACE="Verdana"> </news>< /FONT>
<BR><FONT COLOR="#800000" SIZE=2 FACE="Verdana"></element></FONT> </P>
<P><FONT COLOR="#800000" SIZE=2 FACE="Verdana">Using a stylesheet which specifies that the news element should be cdata:</FONT>
<BR><FONT COLOR="#800000" SIZE=2 FACE="Verdana"><xsl:output method="xml " encoding="ISO-8859-1" cdata-section-elements="<SPAN LANG= "en-ca">headline news</SPAN><SPAN LANG="en-us">"</SPAN><SPAN LANG="en-ca"> m</SPAN><SPAN LANG="en-us">edia-type="text/xml" standalone="no " /></SPAN></FONT></P> <BR>
<P><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">- I'm currently using Xalan 2.4.1 (unpatched).</FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">- This is a servlet using Tomcat 4.12</FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">- My web-inf /lib contains (xml related) jaxb-api.jar, jaxb-libs.jar, jaxb-ri.jar, jaxen-full .jar, xalan.jar, xerces.jar and xercesImpl.jar</FONT></SPAN></P>
<P><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">Here's some sample code on how I'm doing it all:</FONT></SPAN> </P>
<P><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">JAXBSource source = null;</FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">JAXBContext jc = JAXBContext.newInstance("blabla");</FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana" >ObjectFactory factory = new ObjectFactory(); </FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">List objects = null; </FONT>< /SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">Marshaller marshaller = jc.createMarshaller();</FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">.... </FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">source = new JAXBSource(jc, dgn); </FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">marshaller .marshal(dgn, System.out);</FONT></SPAN>
<BR><SPAN LANG="en-us"> </SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">System .setProperty("javax.xml.transform.TransformerFactory", "org .apache.xalan.processor.TransformerFactoryImpl");</FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana" >TransformerFactory tf = TransformerFactory.newInstance(); </FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">Transformer t = tf.newTransformer(new StreamSource("mysheet.xslt"));</FONT></SPAN >
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">t.transform (source, new StreamResult(transformedOut));</FONT></SPAN>
<BR><SPAN LANG="en-us"> </SPAN> </P>
<P><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">The marshal statement sends a string of xml back without any CDATA nodes. I rely on the Transform to do that.</FONT></SPAN> </P>
<P><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">I would like to upgrade to 2.5.1d but can't because I keep getting this error as soon as I replace the jar:</FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">The output format must have a '{</FONT></SPAN><A HREF="http://xml.apache.org/xslt}content -handler"><SPAN LANG="en-us"><U></U><U><FONT COLOR="#0000FF" SIZE=2 FACE= "Verdana">http://xml.apache.org/xslt}content-handler</FONT></U></SPAN></A><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">' property</FONT>< /SPAN> </P>
<P><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">So I'm stuck with 2.4.1 unless I resolve this other problem.</FONT></SPAN> </P>
<P><SPAN LANG="en-us"><FONT COLOR="#800000" SIZE=2 FACE="Verdana">Thanks for any input.</FONT></SPAN> </P> <BR> <BR> <BR>
</BODY> </HTML>
|
|
 |