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

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

问题描述

我需要使用 JAXB Marshaller(JAXB 2.2 版)将 XML java 对象序列化为 XML 文件.现在在 xml 对象中,我有一个包含 String value 的标签,这样:

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?

这方面的任何帮助都会很棒..

Any help in this regard will be great..

提前致谢,阿比纳夫·米什拉

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天全站免登陆