元素文本中'&'的 XML 解析问题继续



对于中讨论的问题';的XML解析问题'在元素文本中我也遇到了同样的问题,但在处理之前用&替换&并不能解决问题

这是我的代码:

convertedString = convertedString.replaceAll("& ", "&");
convertedString = StringEscapeUtils.unescapeHtml(convertedString);

这是我的错误:

[Fatal Error] :1:253: The entity name must immediately follow the '&' in the entity reference.
org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)

如果有人能提供帮助,我们将不胜感激,非常感谢

convertedString = StringEscapeUtils.unescapeHtml(convertedString);
convertedString = convertedString.replaceAll("& ", "& "); // Also note the added space

CCD_ 3实际上将CCD_ 4转换回CCD_。

谢谢Arjan,对不起,这可能是问错了问题。我刚刚意识到,抱怨的是DocumentBuilder解析器,它不接受包含符号的xml,例如:"<text> Health & Safety </text>"。然而,我的客户要求在xml内容中包含符号,除非有其他方法绕过DOMParser,否则我必须操纵前端,即jsp显示&而不是&amp;

最新更新