如何编写 XML Schema 以在 XML 中要求自闭合标记 [英] How to write XML Schema to require self-closing tag in XML

查看:28
本文介绍了如何编写 XML Schema 以在 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 标签中没有内容.所以我想用 <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.

推荐答案

</page-count> 在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆