users@jaxb.java.net

Re: Escape special chars in marshaling.

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 22 Mar 2005 15:28:37 -0800

Jagdeep_Singh_at_capgroup.com wrote:
> Hi All,
>
> I am using JAXB 1.0.2. It seems during marshaling special characters are
> converted to underline os specific chars. Look at my schema declaration
> point-(1) below and original XML doc point-(2) below. This xml doc contains
> "&#8217" to represent "'" during content rendering on web page.
> Point-(3) shows the piece of code after JAXB marshal the XML doc.
>
> Now My question is how can I preserve this special character in JAXB.

XML parsers process Unicode character references like &#8217; so there's
really no way to "preserve" them. But you can configure the marshaller
to always use character references for, say, any code beyond ASCII. See
the character-escape example in the distribution.

By default, if you run it on JDK later than 1.3, we use NIO and only
escape characters when it cannot be represented by the current encoding.

I also noticed that you are using a fairly old version of the JAXB RI.
Consider upgrading to more recent versions. The character-escape sample
might not be in your version.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com