XSD for varying element names

懵懂的女人 提交于 2019-12-02 07:01:36

XSD 1.0

The best you can do in XSD 1.0 is allow any elements under Zones:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Zones">
    <xs:complexType>
      <xs:sequence>
        <xs:any processContents="skip" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
   </xs:element>
</xs:schema>

XSD 1.1

In XSD 1.1 you can go further and constrain the names of the children of Zones to start with Z:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
  vc:minVersion="1.1">
  <xs:element name="Zones">
    <xs:complexType>
      <xs:sequence>
        <xs:any processContents="skip" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:assert test="every $e in * satisfies starts-with(local-name($e), 'Z')"/>
    </xs:complexType>
   </xs:element>
</xs:schema>

You could go even further and require that the string after the Z prefix be a number and probably even impose a sorted constraint as well, but this should get you pointed in the right direction.

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