javajaxbescapingcharactermarshalling

Handling XML escape characters (e.g. quotes) using JAXB Marshaller


I need to serialize an XML java object to a XML file using the JAXB Marshaller (JAXB version 2.2). Now in the xml object, I have a tag which contains String value such that:

"<"tagA>
**"<"YYYYY>done"<"/YYYYY>**
"<"/tagA>

Now as you can see that this string value again contains tags. I want this to be written in the same way in the xml file.

But JAXB Marshaller converts these values such as:

"&"lt;YYYYY"&"gt;"&"#xD;done ...& so on

I am not able to treat these escape characters separately using JAXB 2.2 Is it possible anyways?

Any help in this regard will be great..

Thanks in advance, Abhinav Mishra


Solution

  • Done it by setting the following property for the JAXB Marshaller:

    marshaller.setProperty("jaxb.encoding", "Unicode");