How to write XML Schema to require self-closing tag in XML

牧云@^-^@ 提交于 2020-01-05 21:28:12

问题


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>

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.


回答1:


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



来源:https://stackoverflow.com/questions/26924529/how-to-write-xml-schema-to-require-self-closing-tag-in-xml

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