Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Please Note:</strong> I'm the <a href="http://www.eclipse.org/eclipselink/#moxy" rel="nofollow noreferrer"><strong>EclipseLink JAXB (MOXy)</strong></a> lead and a member of the <a href="http://jcp.org/en/jsr/detail?id=222" rel="nofollow noreferrer"><strong>JAXB (JSR-222)</strong></a> expert group.</p> <p>If you use MOXy as your JAXB (JSR-222) provider then you can leverage the <code>@XmlCDATA</code> extension for your use case.</p> <p><strong>Root</strong></p> <p>The <code>@XmlCDATA</code> annotation is used to indicate that you want the contents of a field/property wrapped in a CDATA section. The <code>@XmlCDATA</code> annotation can be used in combination with <code>@XmlElement</code>.</p> <pre><code>package forum14193944; import javax.xml.bind.annotation.*; import org.eclipse.persistence.oxm.annotations.XmlCDATA; @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Root { @XmlCDATA private String name; @XmlCDATA private String surname; @XmlCDATA private String id; } </code></pre> <p><strong>jaxb.properties</strong></p> <p>To use MOXy as your JAXB provider you need to add file named <code>jaxb.properties</code> with the following entry.</p> <pre><code>javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory </code></pre> <p><strong>Demo</strong></p> <p>Below is some demo code to prove that everything works.</p> <pre><code>package forum14193944; import java.io.File; import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("src/forum14193944/input.xml"); Root root = (Root) unmarshaller.unmarshal(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); } } </code></pre> <p><strong>input.xml/Output</strong></p> <p>Below is the input to and output from running the demo code.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;root&gt; &lt;name&gt;&lt;![CDATA[&lt;h1&gt;kshitij&lt;/h1&gt;]]&gt;&lt;/name&gt; &lt;surname&gt;&lt;![CDATA[&lt;h1&gt;solanki&lt;/h1&gt;]]&gt;&lt;/surname&gt; &lt;id&gt;&lt;![CDATA[0]]&gt;&lt;/id&gt; &lt;/root&gt; </code></pre> <p><strong>For More Information</strong></p> <ul> <li><a href="http://blog.bdoughan.com/2010/07/cdata-cdata-run-run-data-run.html" rel="nofollow noreferrer">http://blog.bdoughan.com/2010/07/cdata-cdata-run-run-data-run.html</a></li> <li><a href="http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html" rel="nofollow noreferrer">http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload