首页 > 解决方案 > xml disorder elements with occurs more than 1

问题描述

I want to change complexType in xsd so that it support disorder elements and multiplely occuers elements.

Let's say, I have xsd and config1 as below, and I also want to support both config1 and config2 without changing config1. (config 1 and 2 differs in some element order(IsEnable and Name).) Is that possible?

I try to replace xs:sequence with xs:all, but elements under xs:all can only occuer exact 0 or 1 time.

//xsd
<xs:element name="Config">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="IsEnabled" type="xs:boolean" minOccurs="1" />
        <xs:element name="Name" type="xs:string" minOccurs="1" />
        <xs:element name="Address" type="xs:string" minOccurs="0" maxOccurs="unbounded">
      </xs:sequence>
    </xs:complexType>
  </xs:element>

//config1
<Congfig>
  <IsEnable>true</IsEnable>
  <Name>name</Name>
  <Address>addr1</Address>
  <Address>addr2</Address>
</Config>

//config2
<Congfig>
  <Name>name</Name>
  <IsEnable>true</IsEnable>
  <Address>addr1</Address>
  <Address>addr2</Address>
</Config>

标签: xmlxsd

解决方案


XSD 1.0 不允许您这样做。

您可以在 XSD 1.1 中执行此操作。


推荐阅读