- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Tue, 4 Nov 2003 10:27:02 +0000
- To: "Srinivasan, Sriram" <SSrinivasan@filenet.com>
- Cc: xmlschema-dev@w3.org
Hi Sriram,
> I have to validate the xml so that a Parameter element can have either a
> Value attribute or a Values element, not both and atleast one of them.
> Is there a way to specify it in xml schema.
No. XML Schema can't do test co-occurrence constraints.
You're probably best off using a Schematron schema to supplement your
XML Schema schema. You could do reasonably sophisticated validation
with a Schematron schema, for example:
<sch:rule context="Parameter">
<sch:assert test="@Value or Values">
The parameter must have a Value attribute or a Values child.
</sch:assert>
<sch:report test="@Value and Values">
The parameter must not have a Value attribute and a Values child.
</sch:report>
<sch:report test="substring(@Type, string-length(@Type) - 1) = '[]'
and @Value">
If the type of a parameter is an array then it must not have a
Value attribute.
</sch:report>
<sch:report test="substring(@Type, string-length(@Type) - 1) = '[]'
and not(Values)">
If the type of a parameter is an array then it must have a Values
child element.
</sch:report>
</sch:rule>
<sch:rule context="Values/Value">
<sch:assert test="@Type =
substring(../../@Type, 1, string-length(@Type) - 2)">
The Type attribute must have the same value as the type of the
array.
</sch:assert>
</sch:rule>
Given that you know all the possible types that are allowed, RELAX NG
would also enable you to test your XML quite thoroughly.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
Received on Tuesday, 4 November 2003 05:29:25 UTC