tags:

views:

78

answers:

2

I am connecting to a webservice which has a service deifnition of the following format

<main>
  <header>
     <data>xyz</data>
  </header>
  <test>
   <![CDATA[<xml><a></a><b></b></xml>]]>
  </test> 
</main>

How do I use jaxb to create class file for the cdata strcture

+1  A: 

First define your schema using the xml-schema format (XSD), and then run the xjc compiler (xsd java compiler) to generate your classes. Once you classes are generated you can create your web service using the @WebService annotation. I posted somes examples on my blog a few monthes ago see: http://plindenbaum.blogspot.com/2006/12/java-16-mustang-jaxb-and.html and http://plindenbaum.blogspot.com/2008/11/web-service-for-onsolubility.html.

hope it helps

Pierre
A: 

Hi there.

JAXB will not be able to parse anything wrapped in a CDATA declaration: the XML parser will always report the string.

If you want to parse this, you need to do the following:

  • Run JAXB on the original schema, which will specify the content of "test" as a string or "any" (it has to, otherwise it cannot contain a CDATA declaration!)

  • Run JAXB on the secondary schema, which defines the content of the "test" element.

At runtime, you need to parse the XML document using JAXB, then navigate to the "test" element and parse that element again using JAXB. There won't be another way.

Hope this helps.

xcut