commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nechiporenko, Maxim" <Maxim.Nechipore...@FMR.COM>
Subject RE: Betwixt appears to escape special characters
Date Wed, 24 Mar 2004 14:59:09 GMT
Robert, thank you for the answer. I believe the plan you outlined in the
end of your message is acceptable. 

Thanks,
Max

-----Original Message-----
From: robert burrell donkin
[mailto:robertburrelldonkin@blueyonder.co.uk] 
Sent: Wednesday, March 24, 2004 6:47 AM
To: Jakarta Commons Users List
Subject: Re: Betwixt appears to escape special characters


interesting :)

the standard use case for betwixt is to have properties containing real 
java values which are mapped from the xml by betwixt. that's why all 
characters are appropriately escaped.

AFAIK at the moment, there is no support for properties that need 
mapping to CDATA (since no one's ever presented a use case for this 
before). AIUI if you set '<error>Some Error</error>' as the property 
value then betwixt will correctly escape it. i'm not really clear what 
use case demands escaping through CDATA rather than by escaping each 
character. maybe someone could remind me of an occasion when CDATA 
sections are treated differently.

the easiest way to add this kind of feature would be to add settings 
that escaping to be ignored for some properties. there are a couple of 
drawbacks that i think i can see for this approach:

1. it leads to inconsistency between SAX pipelines and output to 
string. (the downstream SAX consumer must assume that the 
'<![CDATA[...]]/>' must already have been process from something like  
'&lt;![CDATA[&lt;error&gt;...&lt;/error&gt;]]&gt;')
2. it leads to inconsistency between bean property setters and getters: 
when reading a bean, the section wrapping would already have been 
stripped by the xml parser. therefore, the bean would need to be able 
to cope with processing a plain <error>Some Error</error> into a CDATA 
section.

therefore it seems to me to be better to continue with the existing 
strategy. so, the property value would need to be '<error>Some 
Error</code>'. betwixt would then need to recognize that this needs to 
be escaped as CDATA (rather than through character escapes).

would this plan be acceptable?

- robert

On 23 Mar 2004, at 18:03, John Crossman wrote:

> I am also interested in the answer here.
>
> Maxim: How do you get certain elements to be given <![CDATA[ ]]/> 
> treatment?  And is it possible to only have CDATA applied when the 
> contained text-value is HTML or equivalent?  How do we control this in

> the .betwixt file?
>
> Thanks!
>
> J.
>
>
> -----Original Message-----
> From: Nechiporenko, Maxim [mailto:Maxim.Nechiporenko@FMR.COM]
> Sent: Monday, March 22, 2004 10:41 AM
> To: commons-user@jakarta.apache.org
> Subject: Betwixt appears to escape special characters
>
>
>
> I am having trouble marshalling a JavaBean with one of its attribute 
> values set to a text which is an XML  string. It looks like Betwixt 
> escapes special characters coverting them to ASCII. I have a JavaBean 
> Foo.java, and I use Commons Betwixt to marshall JavaBean in XML. Here 
> is what  I am doing:
>
> // JavaBean
> public class Foo
> {
>   private String val = null;
>
>   public void setVal (String val)
>   {
>     this.val = val;
>   }
>
>   public String getVal()
>   {
>     return this.val;
>   }
> }
>
> // Test program
> import java.io.StringWriter;
> import org.apache.commons.betwixt.io.BeanWriter;
>
> public class test
> {
>   public static void main (String [] args)
>   {
>     test t = new test();
>     t.doStuff();
>   }
>
>   public void doStuff()
>   {
>     Foo bean = new Foo();
>     bean.setVal("<![CDATA[<error>Some Error</error>]]");
>
>     StringWriter outputWriter = new StringWriter();
>     BeanWriter beanWriter = new BeanWriter(outputWriter);
>     beanWriter.getXMLIntrospector().setAttributesForPrimitives(false);
>     beanWriter.setWriteIDs(false);
>     beanWriter.enablePrettyPrint();
>     beanWriter.write("foo", bean);
>     System.out.println("XML:  "+ outputWriter.toString());
>   }
>
> The XML I am getting looks the following:
>
> <foo>
>   <val>
>     &lt;![CDATA[&lt;error&gt;Some Error&lt;/error&gt;]]&gt;
>   </val>
> </foo>
>
> when I would need it to be:
>
> <foo>
>   <val>
>     <![CDATA[<error>Some Error</error>]]
>   </val>
> </foo>
>
> I have no issues marshalling this Bean using Castor. Any help on how 
> to get Betwixt to produce the desired  XML string is welcome.
>
> Thanks,
> Max
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message