xml - "Unique Particle Attribution" violation -


i wrote following (simplified) schema validate xml files receive:

<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" elementformdefault="qualified">      <xs:element name="param">         <xs:complextype>             <xs:sequence>                 <xs:element name="radioaddr" type="xs:string" />                 <xs:element name="datatoread" type="xs:integer" minoccurs="0" maxoccurs="1" />                 <xs:choice minoccurs="0" maxoccurs="1">                     <xs:group ref="group1" />                     <xs:group ref="group2" />                     <xs:group ref="group3" />                 </xs:choice>             </xs:sequence>         </xs:complextype>     </xs:element>      <xs:group name="group1">         <xs:sequence>             <xs:element ref="password" />             <xs:element name="radioactivated" type="xs:integer" minoccurs="0" maxoccurs="1" />             <xs:element ref="idnumber" minoccurs="0" maxoccurs="1" />             <xs:element ref="adjustclock" minoccurs="0" maxoccurs="1" />         </xs:sequence>     </xs:group>      <xs:group name="group2">         <xs:sequence>             <xs:element ref="idnumber" minoccurs="0" maxoccurs="1" />             <xs:element ref="password" />             <xs:element ref="adjustclock" minoccurs="0" maxoccurs="1" />         </xs:sequence>     </xs:group>      <xs:group name="group3">         <xs:sequence>             <xs:element ref="idnumber" minoccurs="0" maxoccurs="1" />             <!-- no password here -->             <xs:element ref="adjustclock" minoccurs="0" maxoccurs="1" />         </xs:sequence>     </xs:group>      <xs:element name="password" type="xs:string" />     <xs:element name="idnumber" type="xs:integer" />     <xs:element name="adjustclock" type="xs:integer" />  </xs:schema> 

when validating schema, obtain following error message:

not valid. error - line 5, 25: org.xml.sax.saxparseexception; linenumber: 5; columnnumber: 25; cos-nonambig: password , password (or elements substitution group) violate "unique particle attribution". during validation against schema, ambiguity created 2 particles.

i understand ambiguity can't find solution make schema valid.

a possible solution like

<xs:element name="param>     <xs:complextype>         <xs:choice maxoccurs="unbounded">             <!-- put possible elements here -->         </xs:choice>     </xs:complextype> </xs:element> 

but problem solution lose 1 level of abstraction (the groups) useful me further (i use schema generate java classes jaxb).

so, there way make schema valid using <xs:group> or have flatten schema (like solution mentioned above) ?

update

here examples should allowed xsd:

the minimal allowed:

<param>     <radioaddr>1</radioaddr> </param> 

is legal:

<param>     <radioaddr>1</radioaddr>     <password>1234</password> </param>  <param>     <radioaddr>1</radioaddr>     <password>1234</password>     <radioactivated>1</radioactivated>     <idnumber>12345678</idnumber> </param>  <param>     <radioaddr>1</radioaddr>     <idnumber>12345678</idnumber>     <password>1234</password> </param> 

to beat unique particle attribution violation, have have allow parser unambiguously know stands in grammar without having ahead more 1 element.

the current error arises because not possible know when encountering password element whether parser in group1 or group2 because idnumber optional. might make idnumber mandatory instead, create ambiguity between group2 , group3 on idnumber. might try using ordering differentiate xs:choice groups, you'd find optionality of elements defeating effort. might remove optionality, , if different ordering among groups acceptable, may have answer.

however, rather odd grammar. @ point, you'd better flattening mentioned, rather using unbounded xs:choice, allow arbitrary , unbounded repeats of elements, can retain of occurrence constraints via simple xs:sequence of elements instead:

<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" elementformdefault="qualified">    <xs:element name="param">     <xs:complextype>       <xs:sequence>         <xs:element name="radioaddr" type="xs:string" />         <xs:element name="datatoread" type="xs:integer" minoccurs="0" maxoccurs="1" />         <xs:element name="radioactivated" type="xs:integer" minoccurs="0" maxoccurs="1" />         <xs:element ref="idnumber" minoccurs="0" maxoccurs="1" />         <xs:element ref="password" minoccurs="0"/>         <xs:element ref="adjustclock" minoccurs="0" maxoccurs="1" />       </xs:sequence>     </xs:complextype>   </xs:element>    <xs:element name="password" type="xs:string" />   <xs:element name="idnumber" type="xs:integer" />   <xs:element name="adjustclock" type="xs:integer" />  </xs:schema> 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -