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:[EMAIL PROTECTED] 
Sent: Monday, March 22, 2004 10:41 AM
To: [EMAIL PROTECTED]
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 

Reply via email to