如何编写 XML Schema 以在 XML 中要求自闭合标记 [英] How to write XML Schema to require self-closing tag in XML
问题描述
下面的 XSD 我有带属性的 page-count 元素.
The below XSD I have page-count element with attributes.
<xs:element name="counts">
<xs:complexType>
<xs:sequence>
<xs:element name="page-count">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:NMTOKEN">
<xs:attribute name="count" use="required" type="xs:NCName"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我的问题是如果我在 XML 中有 <page-count id="blabla" name="count"/>
My problem is if I have <page-count id="blabla" name="count"></page-count>
in XML
there is no content in the page-count tag. So I want to self-close the tag with attribute like <page-count id="blabla" name="count" />
我不知道如何为此编写架构以允许自行关闭页面计数标记.
I don't know how write a schema for this allowing self close the page-count tag.
推荐答案
和
在 XML 中是等效的.在这两种情况下,标签内都没有内容.没有办法使用 XML 模式强制执行自关闭标记.
<page-count count="3"></page-count>
and <page-count count="3"/>
are equivalent in XML. In both cases, there's no content inside the tag. There's no way to enforce a self-closing tag using XML schema.
这篇关于如何编写 XML Schema 以在 XML 中要求自闭合标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!