我正在使用 Spring、CXF 和 Hibernate 构建一个 WebService,该服务对我具有只读访问权限的外部数据库执行搜索查询。
问题是数据库中的某些条目在文本字段中具有奇怪的字符(0x2),并且它用于处理/序列化从 Hibernate 会话返回的对象的 CXF 或库(Aegis?)似乎无法处理它:
org.apache.cxf.aegis.DatabindingException: Error writing document.. Nested exception is com.ctc.wstx.exc.WstxIOException: Invalid white space character (0x2) in text to output (in xml 1.1, could output as a character entity)
我该如何解决这个问题?
理想情况下,我可以删除这些字符,因为它们对我的输出并不重要......
谢谢!
/**
* From xml spec valid chars:<br>
* #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]<br>
* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.<br>
* @param text The String to clean
* @param replacement The string to be substituted for each match
* @return The resulting String
*/
public static String CleanInvalidXmlChars(String text, String replacement) {
String re = "[^\u0009\r\n\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF]";
return text.replaceAll(re, replacement);
}
source: http://www.theplancollection.com/house-plan-lated-articles/hexadecimal-value-invalid-characterheplancollection.com/house-plan-lated-articles/hexadecimal-value-invalid-character http://www.theplancollection.com/house-plan-related-articles/hexadecimal-value-invalid-characterheplancollection.com/house-plan-related-articles/hexadecimal-value-invalid-character
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)