xsd - XML schema and problem when deriving from mixed type -


i have following xml schema:

<?xml version="1.0" encoding="utf-8" standalone="no"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema">      <xs:element name="content" type="contenttype"/>      <xs:complextype name="contenttype">         <xs:complexcontent>             <xs:extension base="versionedelementtype">                   <xs:sequence>                        <xs:element name="item" type="itemtype" minoccurs="1" maxoccurs="unbounded" />                 </xs:sequence>             </xs:extension>         </xs:complexcontent>     </xs:complextype>      <xs:complextype name="itemtype" mixed="true">          <xs:complexcontent>             <xs:extension base="itemtypebase">                     <xs:sequence>                            <xs:element name="order" type="xs:unsignedint"/>                         <xs:element name="id" type="xs:string"/>                     </xs:sequence>             </xs:extension>          </xs:complexcontent>     </xs:complextype>      <!-- simple type convert complex type -->     <xs:complextype name="itemtypebase" mixed="true">         <xs:simplecontent>               <xs:extension base="itemdescriptiontype">             </xs:extension>         </xs:simplecontent>     </xs:complextype>      <!-- simple type -string restriction -->     <xs:simpletype name="itemdescriptiontype" >         <xs:restriction base="xs:string">             <xs:minlength value="1"/>             <xs:maxlength value="64"/>         </xs:restriction>        </xs:simpletype>       <xs:complextype name="versionedelementtype">         <xs:attribute name="version" type="xs:string" use="required"/>     </xs:complextype>  </xs:schema> 

which use validate xml instance (i want mix text in 'item' element sub-elements 'order' , 'id'):

<?xml version="1.0" encoding="utf-8"?> <content xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:nonamespaceschemalocation="content.xsd"          version ="1.0">    <item>description here...   <order>2</order>   <id>2</id>   </item>   </content> 

whatever did validation still says taht there error:

the content type of derived type , of base must both mixed or both element-only. type 'itemtype' mixed, base type not.

but can see both types - itemtype , itemtypebase mixed!!

thanks lot sten

first of error see if open schema in visual studio 2010 is:

the derived type , based type must have same content type.

in current schema type itemtypebase defined respect of <xs:simplecontent> , derived type itemtype respect of <xs:complexcontent> not allowed. either allow no sub-elements , use <xs:simplecontent> or use child elements , use <xs:complexcontent>.

i don't , don't use mixed types. if understand correct want make restrictions in text content. want have content length between 1 , 64 characters. <order>2</order>, <id>2</id> , whitespace, inclusive new line characters, part of content. if want <item> has simple content, can not insert child elements inside.

so pragmatical solution go away mixed model , use xml document in form

<?xml version="1.0" encoding="utf-8"?> <content xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:nonamespaceschemalocation="content.xsd"          version ="1.0">     <item>         <description>description here...</description>         <order>2</order>         <id>2</id>     </item> </content> 

where content.xsd is

<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema">      <xs:element name="content" type="contenttype"/>      <xs:complextype name="contenttype">         <xs:sequence>                <xs:element name="item" type="itemtype"                         minoccurs="1" maxoccurs="unbounded" />         </xs:sequence>         <xs:attribute name="version" type="xs:string" use="required"/>     </xs:complextype>      <xs:complextype name="itemtype">          <xs:sequence>             <xs:element name="description" type="itemdescriptiontype"/>             <xs:element name="order" type="xs:unsignedint"/>             <xs:element name="id" type="xs:string"/>         </xs:sequence>     </xs:complextype>      <xs:simpletype name="itemdescriptiontype" >         <xs:restriction base="xs:string">             <xs:minlength value="1"/>             <xs:maxlength value="64"/>         </xs:restriction>        </xs:simpletype>  </xs:schema> 

all simple , clear.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -