Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with JAXB Unmarshaller  RSS feed

 
Tia Haenni
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code in a servlet, and all works great from either a servlet parameter or the servlet input stream.....as long as there are no characters such as & or #. How can I get the unmarshaller to handle special characters? Can I add something to the xml to fix this?



TIA!
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tia,

I'd say the better question is where do these special characters come from! Although you can turn on explicitly XML validation against a DTD or XML schema during the unmarshalling process, I think in this case the problem is most probably that the XML data aren't even well-formed and with correctly escaped special characters like <, > or &.

I must admit that I can't tell ad-hoc how the JAXB unmarshaller handles such kind of invalid XML especially without knowing more about the XML data your servlet gets. But I can tell you that I've successfully used JAXB for very big and even binary data and I was very happy with its ease of use. And perhaps a good idea for your problem would be to look for the source of the trouble, i.e. where these data come from! Maybe you can simply fix the input data and you're done with the rest of the problem!

It would be helpful, too, if you would provide some more details about the XML input data and what error you get from it!

Marco
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe this one will help you handling the said "special" characters:

http://commons.apache.org/lang/api-2.1/org/apache/commons/lang/StringEscapeUtils.html

I've used it to escape and unescape the few reserved characters during the marshalling and unmarshalling process of an application and it worked just fine. This utility class for example correctly converts a "&" character to "&" which you then can use in XML data!

Marco
 
Tia Haenni
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marco! What we're running into is someting like AT&T in a text node and the parser chokes on it. I will give the commons utility a try.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!