Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
680 views
in Technique[技术] by (71.8m points)

java - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...