使用JAXB Marshaller处理XML转义字符(例如,引号) [英] Handling XML escape characters (e.g. quotes) using JAXB Marshaller

查看:4286
本文介绍了使用JAXB Marshaller处理XML转义字符(例如,引号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用JAXB Marshaller(JAXB版本2.2)将XML java对象序列化为XML文件。现在在xml对象中,我有一个包含字符串值的标签,例如:

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>



现在你可以看到这个字符串值再次包含标签。
我想在xml文件中以相同的方式编写。

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.

但是JAXB Marshaller转换这些值,例如:

But JAXB Marshaller converts these values such as:

&lt; YYYYY&gt;&#xD; done ...&

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

我无法使用JAXB单独处理这些转义字符2.2
是否有可能?

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

提前感谢,
Abhinav Mishra

Thanks in advance, Abhinav Mishra

推荐答案

通过为JAXB Marshaller设置以下属性来完成它:

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

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

这篇关于使用JAXB Marshaller处理XML转义字符(例如,引号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆