开发者

Is it possible to have complexType and elements inside but without the sequence part

开发者 https://www.devze.com 2022-12-11 09:44 出处:网络
I hava a xml doc (and complex element) that is similar to this example: <xs:element name=\"employee\">

I hava a xml doc (and complex element) that is similar to this example:

<xs:element name="employee">
 <xs:complexType>
  <xs:sequence>
   <xs:element name="firstname" type="xs:string"/>
   <xs:element name="lastname" type="xs:string"/>
  </xs:sequence>
 </xs:complexType>
</xs:element>

But in my xml it shouldn't matter if I add firstname or lastname first. So I would like to remove the "xs:sequence" part but I am not sure what I should replace it with.

If it is not poss开发者_如何学运维ible - then why is it not possible?

Update: If I change it with < cx:all> I get this error: "The {max occurs} of all the {parties} of an all group must be 0 or 1".


Use <xs:all> instead of <xs:sequence>:

<xs:element name="employee">
 <xs:complexType>
  <xs:all>
   <xs:element name="firstname" type="xs:string"/>
   <xs:element name="lastname" type="xs:string"/>
  </xs:all>
 </xs:complexType>
</xs:element>

See the W3Schools page on the schema indicators:

All Indicator

The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once:


<xs:element name="employee">
    <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="firstname" type="xs:string" />
            <xs:element name="lastname" type="xs:string" />
        </xs:choice>
   </xs:complexType>
</xs:element>

This will allow you to have elements in any sequence and quantity.


You want the All indicator (<xs:all>).

<xs:element name="employee">
  <xs:complexType>
    <xs:all>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:all>
 </xs:complexType>
</xs:element>

The XML Schema Tutorial on W3Schools is very helpful.

0

精彩评论

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