Validate xml schema containing boolean values

Hi, I have xml:

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

I need to create a scheme to check it in such a way that it allows only 1 to be set to true (and the rest of them must be false [attribute attribute is defined as xs: boolean]), so I added a unique check in the element name as:

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

Of course, he will find that there is a duplicate "truth", but he will also find a duplicate "false". Does anyone know if there is a way to set a limit on which value to apply a unique restriction? that I can guarantee that only one of them is "true" at any given time

+4
source share
1 answer

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

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

However, if you are using Saxon 9.2 , it has preliminary support for XML Schema 1.1. See the function grid to determine which version is needed to verify the circuit.

+2
source

All Articles