开发者

How to define groups of required attributes in XSD?

Supp开发者_开发技巧ose I want element XXX can have either attribute AAA along with attribute BBB in pair or attribute CCC along with DDD in pair but never mix AAA with DDD or similiar.

How can I define this?

Thanks


This is not available functionality within xsd. If you want to restrict attributes to two groupings then you will need to define two elements, one for each of the attribute groupings. For example:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:choice>
        <xs:element name="MyType1">
          <xs:complexType>
            <xs:attribute name="AAA" type="xs:string" />
            <xs:attribute name="DDD" type="xs:string" />
          </xs:complexType>
        </xs:element>
        <xs:element name="MyType2">
          <xs:complexType>
            <xs:attribute name="BBB" type="xs:string" />
            <xs:attribute name="CCC" type="xs:string" />
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

Hope this helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜