xml - XSD for Alternating Elements -


i have following xml shown below:

<?xml version="1.0" encoding="utf-8"?> <main>   <bbcor location="string" name="string">     <pipediameter_inch>3.1415926535</pipediameter_inch>     <initialpressure_psi>3335.566</initialpressure_psi>     <lwise totalsection="2">       <dl_ft>535.00</dl_ft>            <hl_ft>653.00</hl_ft>       <dl_ft>245.98</dl_ft>            <hl_ft>395.0</hl_ft>     </lwise>   </bbcor> </main> 

i trying make xsd validator above file, stuck in alternating elements i.e.

<dl_ft>2.4</dl_ft> <hl_ft>234.00</hl_ft> <dl_ft>3.5</dl_ft> <hl_ft>456.00</hl_ft> <dl_ft>6.8</dl_ft> <hl_ft>678.00</hl_ft> 

i tried online generators etc, none provided required xsd. current xsd file shown below:

<?xml version="1.0" encoding="utf-8"?> <xsd:schema attributeformdefault="unqualified"             elementformdefault="qualified"              version="1.0" xmlns:xsd="http://www.w3.org/2001/xmlschema">   <xsd:element name="main">     <xsd:complextype>       <xsd:sequence>         <xsd:element name="bbcor">           <xsd:complextype>             <xsd:sequence>               <xsd:element name="pipediameter_inch" type="xsd:decimal" />               <xsd:element name="initialpressure_psi" type="xsd:decimal" />               <xsd:element name="lwise">                 <xsd:complextype>                   <xsd:sequence>                     <xsd:element maxoccurs="unbounded" name="dl_ft" type="xsd:decimal" />                     <xsd:element maxoccurs="unbounded" name="hl_ft" type="xsd:decimal" />                   </xsd:sequence>                   <xsd:attribute name="totalsection" type="xsd:int" />                 </xsd:complextype>               </xsd:element>             </xsd:sequence>             <xsd:attribute name="location" type="xsd:string" />             <xsd:attribute name="name" type="xsd:string" />           </xsd:complextype>         </xsd:element>       </xsd:sequence>     </xsd:complextype>   </xsd:element> </xsd:schema> 

what wrong above xsd? using xmllint validate above xml file. xsd not allow alternate elements? worked when elements occurred

<dl_ft>2.45</dl_ft>  <dl_ft>2.44</dl_ft> <dl_ft>2.35</dl_ft> <hl_ft>245</hl_ft> <hl_ft>445</hl_ft> <hl_ft>545</hl_ft> 

you close. factor maxoccurs="unbounded" out xsd:sequence.

specifically, change

              <xsd:sequence>                 <xsd:element maxoccurs="unbounded" name="dl_ft" type="xsd:decimal" />                 <xsd:element maxoccurs="unbounded" name="hl_ft" type="xsd:decimal" />               </xsd:sequence> 

to

              <xsd:sequence maxoccurs="unbounded">                 <xsd:element name="dl_ft" type="xsd:decimal" />                 <xsd:element name="hl_ft" type="xsd:decimal" />               </xsd:sequence> 

because it's dl_ft-hl_ft pairs meant repeated indefinitely.


update:

half pairs

i amiss in not mentioning above solution simple only because examples pair-based. (thanks michael kay reminder.) should need allow non-paired stragglers such lone dl_ft straggler after normal pair,

<dl_ft>2.4</dl_ft> <hl_ft>234.00</hl_ft> <dl_ft>3.5</dl_ft> <-- no hl_ft here --> 

you'll run classic, hopelessly ambiguous, content model issue , won't able check such pattern via xsd. relax ng represent pattern, however.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -