Is there a way to allow the 'this' attribute or the "this other" attribute, but not both?

I am trying to resolve two attribute values ​​for one element. This is how I did it now, but I only want 1 of 2, but not both.

<contact phoneH="cell">8025550000</contact>
<contact phoneW="work"> 8025550094</contact>

      

I want to do something like this:

<xsd:attribute name="phoneH|phoneW" type="xsd:string" />

      

Is there a way to use a constraint element with attributes?

Thanks,
Levy

+2


source to share


2 answers


You cannot do this with the W3C xsd.



An alternative would be to create phoneH and phoneW subelements and use xs:choice

to restrict the user to one or another subelement.

+1


source


I do not believe that restricting an attribute is possible with XML Schema.

You can apply additional validation mechanisms (like schematron ) or use a different schema implementation (i.e. Relax-NG )



http://lists.xml.org/archives/xml-dev/200107/msg00070.html

Unfortunately, you cannot do this with the W3C XML Schema. As I see it, you have two options:

1) Switch to another dialect schema (I think RELAX-NG supports this functionality) 2) Express you joint constraint using the built-in schema rule

These constraints can be checked with Topologi's new Schematron validator. The tool is free and can be downloaded from www.topologi.com.

+1


source







All Articles