我正在尝试用javax.xml.bind.Unmarshaller
解组XML字符串,但收到以下错误:
Caused by: org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x13) was found in the element content of the document.
是否有任何通用解决方案从输入字符串中删除所有非法XML字符?
例如,我尝试使用以下一个,但它没有帮助:
public static String illegalXML11CharactersPattern = "[^"
+ "\u0001-\uD7FF"
+ "\uE000-\uFFFD"
+ "\ud800\udc00-\udbff\udfff"
+ "]+";
public static String stripNonValidXML11Characters(String xml) {
return xml.replaceAll(illegalXML11CharactersPattern, "");
}
最后,我完成了以下方法:
xml = org.apache.commons.lang3.StringEscapeUtils.unescapeXml(StringEscapeUtils.escapeXml10(xml));