xsd validation - I need to validate this xml with xsd -


my xml file is

<?xml version="1.0" encoding="utf-8"?> <edge xmlns="http://www.example.org/stext"> <ellipse rx="189" ry="22" cx="279" cy="531"     style="fill:#fffdfd;stroke:#000000;" id="ellipse_23" islocked="false" /> <ellipse rx="130" ry="38" cx="580" cy="393"     style="fill:#fffdfd;stroke:#000000;" id="ellipse_19" islocked="false" /> <ellipse rx="172" ry="92" cx="539" cy="245"     style="fill:#bd7272;stroke:#d9b5b5;" id="ellipse_20" islocked="false" /> <circle r="51" cx="426" cy="284" style="fill:#bd7272;stroke:#d9b5b5;"     id="circle_16" islocked="false" /> <circle r="45" cx="428" cy="397" style="fill:#fffdfd;stroke:#302e2e;"     id="circle_17" islocked="false" /> </edge> 

this xsd schema

<?xml version="1.0" encoding="utf-8"?> <schema xmlns="http://www.w3.org/2001/xmlschema" targetnamespace="http://www.example.org/stext" xmlns:tns="http://www.example.org/stext" elementformdefault="qualified"> <element name="edge">     <complextype>         <sequence>              <element name="circle" maxoccurs="unbounded">                 <complextype>                     <attribute name="r" type="int" />                     <attribute name="cx" type="int" />                     <attribute name="cy" type="int" />                     <attribute name="style" type="string" />                     <attribute name="id" type="string" />                     <attribute name="islocked" type="boolean" />                 </complextype>             </element>             <element name="ellipse" maxoccurs="unbounded">                 <complextype>                     <attribute name="rx" type="int" />                     <attribute name="ry" type="int" />                     <attribute name="cx" type="int" />                     <attribute name="cy" type="int" />                     <attribute name="style" type="string" />                     <attribute name="id" type="string" />                     <attribute name="islocked" type="boolean" />                 </complextype>             </element>         </sequence>     </complextype> </element> </schema> 

i faced kind of exception

exception: cvc-complex-type.2.4.a: invalid content found starting element 'ellipse'. 1 of '{"http://www.example.org/stext":circle}' expected.

this happens, because <sequence> imposes specific order.

i think might solve problem, use additional xsd:choice element.

if write like

<sequence>    <choice  maxoccurs="unbounded">         <element name="circle">             <complextype>                 <attribute name="r" type="int" />                 <attribute name="cx" type="int" />                 <attribute name="cy" type="int" />                 <attribute name="style" type="string" />                 <attribute name="id" type="string" />                 <attribute name="islocked" type="boolean" />             </complextype>         </element>         <element name="ellipse">             <complextype>                 <attribute name="rx" type="int" />                 <attribute name="ry" type="int" />                 <attribute name="cx" type="int" />                 <attribute name="cy" type="int" />                 <attribute name="style" type="string" />                 <attribute name="id" type="string" />                 <attribute name="islocked" type="boolean" />             </complextype>         </element>     </choice>     </sequence> 

that allow multiple circle or ellipse elements in order.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -