假设我有一个带有描述字段的对象。该字段可以有一个带有一些 html 标记的字符串值。
"Say <b xmlns="http://www.w3.org/1999/xhtml">Hello</b> Wold"
当此对象被编码时,我检索到具有以下结果的 XML
<description>Say <b>Hello</b> World</description>
相反,我希望 html 标记保持未转义
<description>Say <b xmlns="http://www.w3.org/1999/xhtml">Hello</b> World</description>
有没有办法通过例如在我的字段上添加注释来实现这一点?
感谢帮助
最佳答案
以下是防止 Marshaller 转义 HTML 特殊字符的正确方法:
marshaller.setProperty("com.sun.xml.bind.characterEscapeHandler", new CharacterEscapeHandler() {
@Override
public void escape(char[] ch, int start, int length, boolean isAttVal,
Writer out) throws IOException {
out.write(ch, start, length);
}
});
关于jaxb - 防止 JAXB 在我的元素中转义 HTML 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10821238/