xml - Repeating element after xsd:all -


i'd ask if possible allow 1 element repeated after xsd:all. this:

<xsd:complextype name="animal">             <xsd:all>         <xsd:element name="name" type="nametype"/>         <xsd:element name="price" type="salarytype"/>     </xsd:all>             <xsd:element name="note" type="xsd:string" minoccurs="0" maxoccurs="unbounded"/> </xsd:complextype> 

this not valid because there cannot element after xsd:all, how can achieve this?

you can't have element child of complextype. need all group inside sequence, illegal (all has top level of complex type, , can't contain groups - elements , references). all restricted want.

a solution not use all use different group , configure behaves group declared. here alternatives. can choose 1 works or experiment bit , adapt one.

1) choice element allows select 1 group. declaring choice group maxoccurs="unbounded" give similar effect, , can nest choice inside sequence obtaining expect:

<xsd:complextype name="animal">        <xsd:sequence>         <xsd:choice maxoccurs="unbounded">             <xsd:element name="name" type="xsd:string"/>             <xsd:element name="price" type="xsd:string"/>         </xsd:choice>         <xsd:element name="note" type="xsd:string" minoccurs="0" maxoccurs="unbounded"/>       </xsd:sequence> </xsd:complextype> 

only 1 element selected choice, since can have many choice groups, effect allow have many elements in order. it's not 100% equivalent all though: since there no minoccurs need have @ least 1 price or 1 name, doesn't required both. valid:

<price></price> <name></name> <name></name> <name></name> <price></price> <name></name> <price></price> <price></price> <note></note> <note></note> <note></note> 

and this:

<price></price> <name></name> 

but this:

<price></price> 

and fail if there nothing or note.

2) if need guarantee both present pair, need sequence:

<xsd:sequence>     <xsd:sequence maxoccurs="unbounded">         <xsd:element name="name" type="xsd:string"/>         <xsd:element name="price" type="xsd:string"/>     </xsd:sequence>     <xsd:element name="note" type="xsd:string" minoccurs="0" maxoccurs="unbounded"/> </xsd:sequence> 

this make validation fail if price or name present, fail if price comes before name because enforces order.

3) if want allow name/price pair in any order, can declare choice containing 2 sequences:

<xsd:complextype name="animal">        <xsd:sequence>         <xsd:choice maxoccurs="unbounded">             <xsd:sequence>                 <xsd:element name="name" type="xsd:string"/>                 <xsd:element name="price" type="xsd:string"/>             </xsd:sequence>             <xsd:sequence>                 <xsd:element name="price" type="xsd:string"/>                 <xsd:element name="name" type="xsd:string"/>             </xsd:sequence>         </xsd:choice>         <xsd:element name="note" type="xsd:string" minoccurs="0" maxoccurs="unbounded"/>       </xsd:sequence> </xsd:complextype> 

but allow name/price pairs in order. still can't have:

<price/> <price/> <name/> 

4) if wan't allow names , prices in order, allow unbalanced pairs, , no names or prices, or empty animal, use this:

<xsd:element name="animal" type="animal" /> <xsd:complextype name="animal">        <xsd:sequence>         <xsd:sequence maxoccurs="unbounded" minoccurs="0">             <xsd:element name="name" type="xsd:string"/>             <xsd:element name="price" type="xsd:string"/>         </xsd:sequence>         <xsd:sequence maxoccurs="unbounded" minoccurs="0">             <xsd:element name="price" type="xsd:string"/>             <xsd:element name="name" type="xsd:string"/>         </xsd:sequence>         <xsd:element name="note" type="xsd:string" minoccurs="0" maxoccurs="unbounded"/>     </xsd:sequence> </xsd:complextype> 

none of these same all but, depending on needs, 1 of them or combination might fit needs.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -