XML schema validation, how to ignore tree inside element -


considering xml:

<myname myclass="grandfather" name="grandfather_name" transaction="new"> <attributes>     <name>test name</name>     <description>some stuff desc</description>     <version>the current version</version> </attributes> <myname myclass="father" name="father_name" transaction="new">     <attributes>     <name>test name</name>     <description>some stuff desc</description>     <version>the current version</version>     <wifename>name of wife</wifename>     </attributes>     <myname myclass="child_1" name="child_1_name" transaction="new">         <attributes>             <name>test name</name>             <description>some stuff desc</description>             <version>the current version</version>             <girlfriendname>name of girlfriend</girlfriendname>         </attributes>     </myname>     <myname myclass="child_2" name="child_2_name" transaction="new">         <attributes>             <name>test name</name>             <description>some stuff desc</description>             <version>the current version</version>             <girlfriendname>name of girlfriend</girlfriendname>         </attributes>     </myname> </myname> 

i want validate "grandfather" , attributes, , ignore rest of xml. reason added line in schema: type="xs:anytype"

this line causes validation ignore "father", validation failing in "child_1" , "child_2".

"invalid content found starting element 'girlfriendname'. no child element expected @ point"

the xsd in use this:

<?xml version="1.0" encoding="utf-8"?> 

<xs:group name="attributesgroup">      <xs:all>         <xs:element name="name" type="xs:string" minoccurs="1" maxoccurs="1" />         <xs:element name="description" type="xs:string" minoccurs="0" maxoccurs="1" />         <xs:element name="version" type="xs:string" minoccurs="0" maxoccurs="1" />     </xs:all> </xs:group>  <!-- base complex types definitions -->  <xs:complextype name="mycomplextype">     <xs:sequence>         <xs:element name="attributes" minoccurs="1" maxoccurs="unbounded">             <xs:complextype>                     <xs:group ref="attributesgroup"/>             </xs:complextype>         </xs:element>          <xs:element name="myname" type="xs:anytype" minoccurs="0" maxoccurs="unbounded"/>      </xs:sequence>      <xs:attribute name="myclass" type="xs:string" use="required" />     <xs:attribute name="name" type="xs:string" />     <xs:attribute name="transaction" type="xs:string" use="required" /> </xs:complextype>   <!-- root element --> <xs:element name="myname" type="mycomplextype" /> 

how can ignore below "father" ?

you can use xsd:any in locally defined myname within mycomplextype; following xsd validate xml successfully:

<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"            elementformdefault="unqualified">     <xs:group name="attributesgroup">          <xs:all>             <xs:element name="name" type="xs:string" minoccurs="1" maxoccurs="1" />             <xs:element name="description" type="xs:string"                   minoccurs="0" maxoccurs="1" />             <xs:element name="version" type="xs:string" minoccurs="0" maxoccurs="1" />         </xs:all>     </xs:group>     <xs:complextype name="mycomplextype">         <xs:sequence>             <xs:element name="attributes" minoccurs="1" maxoccurs="unbounded">                 <xs:complextype>                     <xs:group ref="attributesgroup"/>                 </xs:complextype>             </xs:element>             <xs:element name="myname" minoccurs="1" maxoccurs="unbounded">                 <xs:complextype>           <xs:sequence>             <xs:any processcontents="skip"                     minoccurs="0" maxoccurs="unbounded"/>           </xs:sequence>           <xs:anyattribute processcontents="skip"/>                 </xs:complextype>             </xs:element>         </xs:sequence>         <xs:attribute name="myclass" type="xs:string" use="required" />         <xs:attribute name="name" type="xs:string" />         <xs:attribute name="transaction" type="xs:string" use="required" />     </xs:complextype>     <xs:element name="myname" type="mycomplextype" /> </xs:schema> 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -