xml - XSD : Unordered list of element that contains xs:any -


i have unordered list of elements contains xs:any , multiple combinations of choice , sequence tried , violate "unique particle attribution". xml following :

<mall id="andaal">     <eff>effrecorder</eff>     <morr>id</morr>     <todd>toddcurrenttype == toddidoldtype</todd>     <mall id="donallid">         <morr>id</morr>         <eff>effrecorder</eff>         <other>quickcode</other>         <mall id="mall2id">             <eff>tickerchaineff</eff>             <morr>sourceid</morr>             <other>tickercode</other>         </mall>     </mall>     <mall id="mall2sourceid">         <eff>listing2sourceeff</eff>         <morr>id</morr>         <other>other2price</other>         <other>expirydate</other>     </mall> </mall> 

the xsd code :

<xs:element name="mall" maxoccurs="unbounded" minoccurs="0">     <xs:complextype mixed="true">         <xs:sequence>             <xs:element type="xs:string" name="eff" minoccurs="0"/>             <xs:element type="xs:string" name="todd" minoccurs="0"/>             <xs:element type="xs:string" name="morr" minoccurs="1"/>             <xs:any minoccurs="0" maxoccurs="unbounded" processcontents="lax" />         </xs:sequence>         <xs:attribute name="id" use="required">             <xs:simpletype>                 <xs:restriction base="xs:string">                     <xs:pattern value="[a-za-z_]+"/>                 </xs:restriction>             </xs:simpletype>         </xs:attribute>     </xs:complextype> </xs:element> 

note elements eff, todd , morr can occur in order, , can occur deeper in hierarchy inside mall element.

xsd 1.0

using xsd 1.0 not possible. parser needs able pick each element , given current state figure out (unambiguously) schema element should use validate it. not support form of ahead. introducing any providing ambiguity, match existing eff,todd,morr elements, resolved looking ahead, thats not supported.

so best this

enter image description here

<?xml version="1.0" encoding="utf-8" ?> <!--created liquid xml 2017 developer bundle edition (trial) 15.0.0.7015 (https://www.liquid-technologies.com)--> <xs:schema elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema">     <xs:element name="mall">         <xs:complextype mixed="true">             <xs:choice minoccurs="0" maxoccurs="unbounded">                 <xs:element name="eff" type="xs:string" minoccurs="0" />                 <xs:element name="todd" type="xs:string" minoccurs="0" />                 <xs:element name="morr" type="xs:string" minoccurs="0" />                 <xs:any minoccurs="0" namespace="##other" processcontents="lax" />             </xs:choice>             <xs:attribute name="id" use="required">                 <xs:simpletype>                     <xs:restriction base="xs:string">                         <xs:pattern value="[a-za-z_]+" />                     </xs:restriction>                 </xs:simpletype>             </xs:attribute>         </xs:complextype>     </xs:element> </xs:schema> 

where any constrained namespace not current targetnamespace. prevents ambiguity , everythings ok.

except....now have schema allows 0-n eff, todd, morr elements. far perfect.

xsd 1.1

you can trying using xsd 1.1 using opencontent element.

enter image description here

<?xml version="1.0" encoding="utf-8" ?> <!--created liquid xml 2017 developer bundle edition (trial) 15.0.0.7015 (https://www.liquid-technologies.com)--> <xs:schema elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema">     <xs:element name="mall">         <xs:complextype mixed="true">             <xs:opencontent mode="interleave">                 <xs:any processcontents="lax" />             </xs:opencontent>             <xs:all>                 <xs:element name="eff" type="xs:string" minoccurs="0" />                 <xs:element name="todd" type="xs:string" minoccurs="0" />                 <xs:element name="morr" type="xs:string" minoccurs="1" />             </xs:all>             <xs:attribute name="id" use="required">                 <xs:simpletype>                     <xs:restriction base="xs:string">                         <xs:pattern value="[a-za-z_]+" />                     </xs:restriction>                 </xs:simpletype>             </xs:attribute>         </xs:complextype>     </xs:element> </xs:schema> 

this enforces cardinality rules placed on eff, todd & morr while allowing put other content in between them i.e.

<?xml version="1.0" encoding="utf-8"?> <!-- created liquid xml 2017 developer bundle edition (trial) 15.0.0.7015 (https://www.liquid-technologies.com) --> <mall xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xsi:nonamespaceschemalocation="schema11.xsd" id="_mi___xw">     <other></other>     <eff>string</eff>     <other></other>     <todd>string</todd>     <other></other>     <morr>string</morr>     <other></other> </mall> 

the downside xsd 1.1 not widley suported yet, xerces , few other parsers support it, not many.

update

updated reflect michael kay's comments. michael points out xsd 1.1 can resolve ambiguity between any , named elements. result simpler.

enter image description here

<?xml version="1.0" encoding="utf-8" ?> <!--created liquid xml 2017 developer bundle edition (trial) 15.0.0.7015 (https://www.liquid-technologies.com)--> <xs:schema elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema">     <xs:element name="mall">         <xs:complextype mixed="true">             <xs:all>                 <xs:element name="eff" type="xs:string" minoccurs="0" />                 <xs:element name="todd" type="xs:string" minoccurs="0" />                 <xs:element name="morr" type="xs:string" minoccurs="1" />                 <xs:any minoccurs="0" maxoccurs="unbounded" processcontents="lax" />             </xs:all>             <xs:attribute name="id" use="required">                 <xs:simpletype>                     <xs:restriction base="xs:string">                         <xs:pattern value="[a-za-z_]+" />                     </xs:restriction>                 </xs:simpletype>             </xs:attribute>         </xs:complextype>     </xs:element> </xs:schema> 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -