开发者

Unordered list of elements including a choice between 1 element and a sequence of other 3 elements

I have an XML that can be either like this:

<profile>
  <docname>Bla bla bla</docname>
  <author>Bubi</author>
  <doctype>INVOICE</doctype>
</profile>

or like this:

<profile>
  <author>Bubi</author>
  <docname>Bla bla bla</docname>
  <type1>3</type1>
  <type2>1</type2>
  <type3>0</type3>
</profile>

Elements can appear in any order. As you see it is required to have either <doctype> or <type1>, <type2> and <type3> tags.

I need an XSD for it. I tried with

<xs:element name="profile">
  <xs:complexType>
    <xs:all>
      <xs:element type="xs:string" name="author"/>
      <xs:element type="xs:string" name="docname"/>
      <xs:choice>
        <xs:element type="xs:string" name="doctype"/>
        <xs:sequence> <!--another little problem: I'd like to put a <xs:all> but is not allowed...-->
          <xs:element type="xs:byte" name="type1"/>
          <xs:element type="xs:byte" name="type2"/>
          <xs:element type="xs:byte" name="type3"/>
        </xs:sequence>
      </xs:choice>
    </xs:all>
  </xs:complexType>
</xs:开发者_高级运维element>

But <xs:choice> is not allowed inside an <xs:all> (why is <xs:all> so mistreated???). I found this great related solution, but it works only if the choice is among single elements and not among groups of them.

Anyone knows a workaround? Many thanks!


The main issue here has to do with the unique particle attribution. If you have options, a Relax NG schema may help you instead. Otherwise, you'd have to complement a "weaker" XSD (do an xsd:all from all your six elements) with other mechanisms (a simple XSLT or handwritten code, etc.).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜