Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing CDATA using JAXB.

 
Thapliyal Akshat
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Have you tried something along the following lines?

Best wishes!
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Thapliyal Akshat
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic