xsd - XML-Schema : maxOccurs , minOccurs -


when run code gives me error

[ s4s-att-not-allowed: attribute 'maxoccurs' cannot appear in element 'element'.] 

here schema :

<xs:element name="parameters" maxoccurs="1" minoccurs="0">     <xs:complextype>         <xs:all>             <xs:element ref="p ?"/>          </xs:all>     </xs:complextype> </xs:element> 

<xs:element> may declared @ top-level (below xs:schema) can't have minoccurs or maxoccurs since doesn't make sense without context. if it's root can have 1 element, if it's not, information refers context of parent element. legal:

<xs:schema ...>     <xs:element name="parameters">...</xs:element>     ... </xs:schema> 

but not:

<xs:schema ...>     <xs:element name="parameters" maxoccurs="1" minoccurs="0">...</xs:element> ... </xs:schema> 

you can refer top level xs:element within group such xs:sequence. here can use these attributes because have context (how many allowed in group). legal:

<xs:schema ...>     <xs:element name="parent">         <xs:complextype>             <xs:sequence>                  <xs:element ref="parameters" maxoccurs="1" minoccurs="0" />             </xs:sequence>         </xs:complextype>     </xs:element>      <xs:element name="parameters">         <xs:complextype>             <xs:all>                 <xs:element ref="p" minoccurs="0"/>              </xs:all>         </xs:complextype>     </xs:element>     ... </xs:schema> 

here <parent> context <parameters> occurs, can how many times it's allowed in there. definition of <parameters> global , use ref attribute refer it.

if never need reuse parameters or if never going have parameters root, don't need @ top-level , can nest inside parent definition. in case can use name attribute minoccurs , maxoccurs.

<xs:schema ...>     <xs:element name="parent">         <xs:complextype>             <xs:sequence>                  <xs:element name="parameters" maxoccurs="1" minoccurs="0" />                      <xs:complextype>                           <xs:all>                                <xs:element ref="p" minoccurs="0"/>                            </xs:all>                      </xs:complextype>                  </xs:element>             </xs:sequence>         </xs:complextype>     </xs:element>      ... </xs:schema> 

you can refer top-level type. it's more common reuse, extend , restrict types, valid (and recommended) way define element:

<xs:schema ...>     <xs:element name="parent">         <xs:complextype>             <xs:sequence>                  <xs:element name="parameters" type="parametertype" maxoccurs="1" minoccurs="0" />             </xs:sequence>         </xs:complextype>     </xs:element>      <xs:complextype name="parametertype">         <xs:all>             <xs:element ref="p" minoccurs="0"/>          </xs:all>     </xs:complextype>     ... </xs:schema> 

Comments

Popular posts from this blog

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -