Is it possible to make an attribute required iff another attribute is set?
E.g. In the following code, viewId attribute has to be made required, iff action attribute is set.
XML:
<node id="id1" destination="http://www.yahoo.com" />
<node id="id2" action="demo" viewId="demo.asp"/>
If this is possible, could you please show me how this is done. As of now, I have viewId set required in all the cases, because of which the 1st node element fails validation.
<xsd:attribute name="focusViewId" type="xsd:anyURI" use="required"/>
It is not possible with XSD 1.0 alone. You have to employ the use of another XML schema language, in addition to or instead of XSD, or move to XSD 1.1.
Another alternative may be to restructure your schema. If @destination is mutually exclusive with { @action, @viewId} maybe you could use elements instead which would then allow you to employ
xsd:choice.UPDATE: for an XSD 1.1