![](/img/trans.png)
[英]Why must the entity name immediately follow the '&' in the entity reference appearing for the XML?
[英]Validating XML which has '& 'against XSD throws "The entity name must immediately follow the '&' in the entity reference"
我有一个在内容中包含“&”的 xml,我正在尝试使用以下代码验证 xml ganist xsd
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(new StreamSource(xsd)); Validator validator = schema.newValidator(); validator.validate(new StreamSource(xml));
当 XML 没有“&”时,代码工作正常,
但抛出这个错误
当包含 '&' 时,“实体名称必须紧跟在实体引用中的 '&' 之后”。
很高兴接受任何解决此问题的建议。 提前致谢!! :)
编辑:我一直在尝试使用 & 我们必须使用&
解决了 :)
你需要转义像 & 这样的特殊字符。
& 用于表示其他特殊字符,如 <: <
用 & 替换 &
'&' 在 XML 内容中是非法的。 是否允许更改 XML? 您可以使用CDATA 部分包装有问题的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.