aspose file tools*
The moose likes Web Services and the fly likes Parsing CDATA using JAXB. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Parsing CDATA using JAXB." Watch "Parsing CDATA using JAXB." New topic
Author

Parsing CDATA using JAXB.

Thapliyal Akshat
Greenhorn

Joined: Jun 04, 2009
Posts: 29
Hello Everyone,

I am interacting with a web service which is providing me all the data in CDATA. Initially I was invoking a different web service operation which was providing me the response without the CDATA. I am using JAXB to fetch all the data from the reponse and set the appropriate methods. As this method was taking too much time third party vendors suggested us to use another operation.

But the problem with this operation is that it returns all the data wrapped in CDATA due to which my existing code breaks. Below is the sample response.



I was using the JAXB to unmarshal the XML and then fetch all the elements but I am unaware how to fetch the Data from CDATA.

I have also created a schema file for the new output. Using this schema only I am generating my new Java Code



Kindly put some light on how can I extract the data from CDATA using JAXB and Is the above schema is correct for the above response.

Thanks and Regards
Akshat Thapliyal

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Have you tried something along the following lines?

Best wishes!
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Thapliyal Akshat wrote:
But the problem with this operation is that it returns all the data wrapped in CDATA due to which my existing code breaks. Below is the sample response.



This operation seems to have a poor design.

Regards,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Thapliyal Akshat
Greenhorn

Joined: Jun 04, 2009
Posts: 29
Hey Ivan,

Thanks for your precious reply. I was aware of the logic that you have suggested but actually I was looking for some other mechanism through which I can fetch the CDATA for example as we do in XMLBeans by using the getters methods.

After lot of deep thinking in this issue I have got a small resolution which doesn't involve parsing of the CDATA at least.
what I will do is I will fetch all the CDATA using JAXB and using TransformerFactory make it a valid XML and then using XMLBeans I will fetch all the data using the getters.

I know this is not the best solution in town but at least better than parsing a string.


Thanks and Regards,
Akshat Thapliyal
Thapliyal Akshat
Greenhorn

Joined: Jun 04, 2009
Posts: 29
Hi Dan,


Yes the operation has poor design that's what I have conveyed to my PM also. Lets see what the third party vendors will suggest now. We are having a discussion with them if is there any way that we can get data in XML.

So that we don't have to modify our base code.


Thanks and Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing CDATA using JAXB.