使用特殊字符,例如 '+'在 DTD 实体中
我试图定义一个其值包含“+”字符的实体,但如果这样做,我会收到一条奇怪的错误消息。如果我删除+字符,一切正常。我似乎找不到摆脱它的方法。
我不仅在当前使用的库中遇到错误,而且在 http: //www.validome.org/grammar/validate/ 一个简短的示例:
<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY % Foo "BAR"> <!--No problem here-->
<!ENTITY % Baz "QUUX+QUUUX"> <!--This will cause trouble later on-->
<!ENTITY % FooBazType "( %Foo; | %Baz; )">
<!ELEMENT tagName EMPTY>
<!ATTLIST tagName attributeName %FooBazType; #REQUIRED> <!--Here, you get the error message : The enumerated type list must end with ')' in the "attributeName" attribute declaration.-->
有谁知道以某种方式获取 + 字符(或者也能正确验证在该位置包含 + 字符的 XML 文档的方法)的方法吗?提前致谢!
I'm trying to define an entity whose value contains a '+' character, but if I do so, I get a weird error message further down the line. If I remove the + character, everything works fine. I can't seem to figure out a way to escape it.
I get the error not only with the library I'm currently using, but also with the online validator at http://www.validome.org/grammar/validate/
A short sample :
<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY % Foo "BAR"> <!--No problem here-->
<!ENTITY % Baz "QUUX+QUUUX"> <!--This will cause trouble later on-->
<!ENTITY % FooBazType "( %Foo; | %Baz; )">
<!ELEMENT tagName EMPTY>
<!ATTLIST tagName attributeName %FooBazType; #REQUIRED> <!--Here, you get the error message : The enumerated type list must end with ')' in the "attributeName" attribute declaration.-->
Does anyone know of a way to get a + character (or something that'll also correctly validate an XML document that would contain a + character in that location) in there somehow? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于实体本身,而在于它用于定义一个属性,其中 枚举合法值。此类值必须匹配
Nmtoken
(一个或多个NameChar
)。这不包括“+”和“$”,它们不是定义的一部分>NameChar
。下面的例子说明了这一点。plus.dtd:
plus.xml:
尝试根据 plus.dtd 验证 plus.xml 时的 xmllint 输出:
在固定属性值中使用“+”或“$”是可以的。
plus2.dtd:
xmllint 输出(无错误):
The problem is not the entity itself, but the fact that it is used to define an attribute where the legal values are enumerated. Such values must match
Nmtoken
(one or moreNameChar
s). That excludes '+' and '$', which are not part of the definition ofNameChar
. The example below illustrates this.plus.dtd:
plus.xml:
xmllint output when trying to validate plus.xml against plus.dtd:
Using '+' or '$' in a fixed attribute value is OK.
plus2.dtd:
xmllint output (no error):