首页 > 解决方案 > 各种 XML 定义的示例

问题描述

在阅读XML 规范时,它提到了以下定义:

Names and Tokens
[4]     NameStartChar      ::=      ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
[4a]    NameChar           ::=      NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
[5]     Name               ::=      NameStartChar (NameChar)*

Literals
[9]     EntityValue        ::=      '"' ([^%&"] | PEReference | Reference)* '"' |  "'" ([^%&'] | PEReference | Reference)* "'"
[10]    AttValue           ::=      '"' ([^<&"] | Reference)* '"'|  "'" ([^<&'] | Reference)* "'"
[11]    SystemLiteral      ::=      ('"' [^"]* '"') | ("'" [^']* "'")
[12]    PubidLiteral       ::=      '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
[13]    PubidChar          ::=      #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]

什么是名称、实体、属性、SystemLiteral 和 Pubid 的示例(?)

例如在下面:

<Item id="123">Hello<Item/>

Item名称还是实体值?我会假设123"123"将是 Att(ribute)Value。这两个都对吗?其他人的例子是什么?

从规范中说:

文字数据是任何带引号的字符串,不包含用作该字符串分隔符的引号。文字用于指定内部实体的内容 (EntityValue)、属性的值 (AttValue) 和外部标识符 (SystemLiteral)。

因此,我认为Item将是EntityValue123将是AttrValue:那么 PubID 和 SystemLiteral 的示例是什么?最后,为什么不EntityValue排除<>字符?

标签: xmlgrammarcontext-free-grammarw3c

解决方案


您的 XML 示例解析如下:

<Item id="123">Hello<Item/>是一个元素

您的示例中没有以下构造:

  • EntityValue
    示例:"2020"<!ENTITY year "2020">
  • PubidLiteral
    示例:"-//W3C//DTD HTML 4.01//EN"in <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> )
  • SystemLiteral
    示例:"../img/logo.gif"<!ENTITY logo SYSTEM "../img/logo.gif" NDATA gif >

有关如何使用、和的更多上下文,请参阅第4.2 节实体声明EntityValuePubidLiteralSystemLiteral


推荐阅读