使用特殊字符,例如 '+'在 DTD 实体中

发布于 2024-12-23 13:47:08 字数 779 浏览 0 评论 0原文

我试图定义一个其值包含“+”字符的实体,但如果这样做,我会收到一条奇怪的错误消息。如果我删除+字符,一切正常。我似乎找不到摆脱它的方法。
我不仅在当前使用的库中遇到错误,而且在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨敛清荷 2024-12-30 13:47:08

问题不在于实体本身,而在于它用于定义一个属性,其中 枚举合法值。此类值必须匹配 Nmtoken(一个或多个 NameChar)。这不包括“+”和“$”,它们不是定义的一部分>NameChar。下面的例子说明了这一点。

plus.dtd:

<!ELEMENT tagName EMPTY>
<!ATTLIST tagName 
          attributeName (BAR | FOO+BAZ) #REQUIRED>

plus.xml:

<tagName attributeName="FOO+BAZ"/>    

尝试根据 plus.dtd 验证 plus.xml 时的 xmllint 输出:

xmllint --dtdvalid plus.dtd plus.xml 
<?xml version="1.0"?>
<tagName attributeName="FOO+BAZ"/>
plus.dtd:2: parser error : ')' required to finish ATTLIST enumeration
<!ATTLIST tagName attributeName (BAR | FOO+BAZ) #REQUIRED>
                                          ^
plus.dtd:2: parser error : Space required after the attribute type
<!ATTLIST tagName attributeName (BAR | FOO+BAZ) #REQUIRED>
                                          ^
plus.dtd:2: parser error : Content error in the external subset
<!ATTLIST tagName attributeName (BAR | FOO+BAZ) #REQUIRED>
                                          ^
Could not parse DTD plus.dtd

在固定属性值中使用“+”或“$”是可以的。

plus2.dtd:

<!ELEMENT tagName EMPTY>
<!ATTLIST tagName 
          attributeName CDATA #FIXED "FOO+$BAZ">

xmllint 输出(无错误):

xmllint --dtdvalid plus2.dtd plus.xml 
<?xml version="1.0"?>
<tagName attributeName="FOO+$BAZ"/>

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 more NameChars). That excludes '+' and '$', which are not part of the definition of NameChar. The example below illustrates this.

plus.dtd:

<!ELEMENT tagName EMPTY>
<!ATTLIST tagName 
          attributeName (BAR | FOO+BAZ) #REQUIRED>

plus.xml:

<tagName attributeName="FOO+BAZ"/>    

xmllint output when trying to validate plus.xml against plus.dtd:

xmllint --dtdvalid plus.dtd plus.xml 
<?xml version="1.0"?>
<tagName attributeName="FOO+BAZ"/>
plus.dtd:2: parser error : ')' required to finish ATTLIST enumeration
<!ATTLIST tagName attributeName (BAR | FOO+BAZ) #REQUIRED>
                                          ^
plus.dtd:2: parser error : Space required after the attribute type
<!ATTLIST tagName attributeName (BAR | FOO+BAZ) #REQUIRED>
                                          ^
plus.dtd:2: parser error : Content error in the external subset
<!ATTLIST tagName attributeName (BAR | FOO+BAZ) #REQUIRED>
                                          ^
Could not parse DTD plus.dtd

Using '+' or '$' in a fixed attribute value is OK.

plus2.dtd:

<!ELEMENT tagName EMPTY>
<!ATTLIST tagName 
          attributeName CDATA #FIXED "FOO+$BAZ">

xmllint output (no error):

xmllint --dtdvalid plus2.dtd plus.xml 
<?xml version="1.0"?>
<tagName attributeName="FOO+$BAZ"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文