xml - xsd:unique with optional attributes -


i have xml file:

<objects>   <object name="id1" />   <object name="id2" />   <object name="id2" color="green" />   <object name="id3" color="green" /> <objects> 

i validate against xsd schema, combination between name , color unique in document.

the problem that, if use:

<xs:unique name="uniqueobjectnamecolor">   <xs:selector xpath="./object" />   <xs:field xpath="@name" />   <xs:field xpath="@color" /> </xs:unique> 

... rule ignore object elements without optional color attribute. following validates correctly while shouldn't.

  <object name="id2" />   <object name="id2" /> 

can tell me how can specify rule enforces unique name , color combinations and, when color attribute not present in element object, checks name?

use use , default or without value like:

    <element name="objects">         <complextype>             <sequence>                 <element name="object" maxoccurs="unbounded">                     <complextype>                         <attribute name="name" type="string" />                         <attribute name="color" type="string" use="optional" default="nocolor" />                     </complextype>                 </element>             </sequence>         </complextype>         <unique name="uniqueobjectnamecolor">             <selector xpath="tns:object" />             <field xpath="@name" />             <field xpath="@color" />         </unique>     </element>  </schema> 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -