views:

79

answers:

1

Hi I have a xml like this:

<xml><fullname>
<name attrib="true"/>
<lastname1 attrib="false"/>
<lastname2 attrib="false"/></fullname></xml>

I need to create a schema to validate it in such a way that it will allow only 1 attrib with value "true" (and the rest of them must be false [the attrib attribute is defined to be xs:boolean]), so i added a unique check in the element fullname like this:

   <xs:unique name="attribcheck">
<xs:selector xpath="name|lastname1|lastname2"/>
<xs:field xpath="@attrib"/>

Of course, it will detect that there is a duplicated "true", but also, it will detect a duplicated "false". Does anyone know if there is a way to set a restriction on which value to apply the unique constraint? meaning that i can ensure that only one of them is "true" at any given time

+2  A: 

XML Schema 1.0 does not support co-occurrence constraints - you cannot express a condition on one element based on the value of another.

This will change in XML Schema 1.1, but the latter is only in draft stage and is still changing, and will not be widely implemented for some time.

However, if you use Saxon 9.2, it has preliminary support for XML Schema 1.1 now. See the feature grid to determine which version is needed for schema validation.

lavinio
Thanks, i guess i'll try to use the preliminary support for schema 1.1
amorales