XML 中的 <tag /> 和 <tag></tag> 之间是否存在语义差异?
Is there a semantic difference between <tag /> and <tag></tag> in XML?
我们遇到了一些客户的问题,客户争论说我们发送的 XML 文件中两个版本的空标签之间存在语义差异(纯 XML 没有 HTML..).
他们期望:
<our-xml>
<some-tag></some-tag>
</our-xml>
我们发送:
<our-xml>
<some-tag />
</our-xml>
我们认为这完全一样,但我们无法真正用事实证明这些论点。我们唯一找到的东西是 https://www.w3.org/TR/REC-xml/#sec-starttags 上面写着
empty-element tags may be used for any element which has no content.
有没有我们可以依赖的讨论或更清晰的论文,或者我们错了吗?
没有
Start-tag/End-tag (<tag></tag>
) 和空元素标记 (<tag/>
) 形式在语义上是等价的。 没有符合规范的 XML 解析器会区别对待它们。
参考:
Extensible Markup Language (XML) 1.0 (Fifth Edition)
3.1 Start-Tags, End-Tags, and Empty-Element Tags
-
Empty-element tags may be used for any element which has no content, whether or not it is declared using the keyword EMPTY.
历史记录: 还有一个过时的 SGML 兼容性参考,为了完整起见,我将其包括在内:
For interoperability, the empty-element tag should be used, and should only be used, for elements which are declared EMPTY.
-
for interoperability
[Definition: Marks a sentence describing a non-binding recommendation included to increase the chances that XML documents can be processed by the existing installed base of SGML processors which predate the WebSGML Adaptations Annex to ISO 8879.]
相关Q/A:
- Self-closing tags in XML files
我们遇到了一些客户的问题,客户争论说我们发送的 XML 文件中两个版本的空标签之间存在语义差异(纯 XML 没有 HTML..).
他们期望:
<our-xml>
<some-tag></some-tag>
</our-xml>
我们发送:
<our-xml>
<some-tag />
</our-xml>
我们认为这完全一样,但我们无法真正用事实证明这些论点。我们唯一找到的东西是 https://www.w3.org/TR/REC-xml/#sec-starttags 上面写着
empty-element tags may be used for any element which has no content.
有没有我们可以依赖的讨论或更清晰的论文,或者我们错了吗?
没有
Start-tag/End-tag (<tag></tag>
) 和空元素标记 (<tag/>
) 形式在语义上是等价的。 没有符合规范的 XML 解析器会区别对待它们。
参考: Extensible Markup Language (XML) 1.0 (Fifth Edition)
3.1 Start-Tags, End-Tags, and Empty-Element Tags
-
Empty-element tags may be used for any element which has no content, whether or not it is declared using the keyword EMPTY.
-
历史记录: 还有一个过时的 SGML 兼容性参考,为了完整起见,我将其包括在内:
For interoperability, the empty-element tag should be used, and should only be used, for elements which are declared EMPTY.
-
for interoperability
[Definition: Marks a sentence describing a non-binding recommendation included to increase the chances that XML documents can be processed by the existing installed base of SGML processors which predate the WebSGML Adaptations Annex to ISO 8879.]
相关Q/A:
- Self-closing tags in XML files