开发者

Extension in XMlSchema, how to?

开发者 https://www.devze.com 2022-12-20 03:53 出处:网络
I have written a XMLSchema which looks like the one below. The idea is that baseContainer only allows some tags and fullContainer allows all tags in baseContainer + some other tags. The tags may come

I have written a XMLSchema which looks like the one below. The idea is that baseContainer only allows some tags and fullContainer allows all tags in baseContainer + some other tags. The tags may come in any order and there can be multiple of all the tags. In my real sample there is a lot more tags so this method of write XMLSchema tends to become big and unstructured. I want to use XMLSchema extension tag to structure the doc but it do not work as I expect.

Thanks in advance :)

<complexType name="baseContainer">
  <sequence minOccurs="0" maxOccurs="unbounded">
    <choice minOccurs="0" max开发者_C百科Occurs="1">
      <element ref="w:aTag0"/>
      <element ref="w:aTag1"/>
      <element ref="w:aTag2"/>
    </choice>
  </sequence>
</complexType>

<complexType name="fullContainer">
  <sequence minOccurs="0" maxOccurs="unbounded">
    <choice minOccurs="0" maxOccurs="1">
      <element ref="w:aTag0"/>
      <element ref="w:aTag1"/>
      <element ref="w:aTag2"/>
      <element ref="w:aTag3"/>
      <element ref="w:aTag4"/>
    </choice>
  </sequence>
</complexType>

I have tried this:

<complexType name="fullContainer">
  <complexContent>
    <extension base="w:baseContainer">
      <sequence minOccurs="0" maxOccurs="unbounded">
        <choice minOccurs="0" maxOccurs="1">
          <element ref="w:aTag3"/>
          <element ref="w:aTag4"/>
        </choice>
      </sequence>
    </extension>
  </complexContent>
</complexType>


As far a I know, what you want is not possible in xml-schema. You can extend (or restrict) a defined type. But you cannot extend a choice element.

0

精彩评论

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