Is there a semantical difference between <tag /> and <tag></tag> in XML?

巧了我就是萌 提交于 2019-12-30 05:25:10

问题


We have some kind of problem with a customer which is arguing that there is a semantical difference between two versions of empty tag in an XML file we're sending (pure XML no HTML..).

They expect:

 <our-xml>
    <some-tag></some-tag>
 </our-xml>

We send:

 <our-xml>
    <some-tag />
 </our-xml>

We are of the opinion that this is exactly the same but we could not really prove the arguments with facts. Only thing we found was in https://www.w3.org/TR/REC-xml/#sec-starttags where it says

empty-element tags may be used for any element which has no content.

Is there any discussion or more clear paper that we can rely on or are we wrong?


回答1:


No

Start-tag/End-tag (<tag></tag>) and Empty-element tag (<tag/>) forms are semantically equivalent. No conforming XML parser will treat them differently.


Reference: Extensible Markup Language (XML) 1.0 (Fifth Edition)

  • 3.1 Start-Tags, End-Tags, and Empty-Element Tags

    • Tags for Empty Elements

      Empty-element tags may be used for any element which has no content, whether or not it is declared using the keyword EMPTY.


Historical note: There is also an antiquated SGML compatibility reference, which I include for completeness:

For interoperability, the empty-element tag should be used, and should only be used, for elements which are declared EMPTY.

  • 1.2 Terminology

    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.]


Related Q/A:

  • Self-closing tags in XML files
  • Create XML element without closing tag
  • Is XML's root closing tag mandatory?
  • XML with end tag and without it (self-closing tag)
  • What does <tag/> mean in XML?


来源:https://stackoverflow.com/questions/57494936/is-there-a-semantical-difference-between-tag-and-tag-tag-in-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!