[
Lists Home |
Date Index |
Thread Index
]
MessageFrom: Prasad G S K
>Can I define this kind of restriction/dependency in XSD files?
No, you can't constrain content models in this way using xsd. The best you
can do is something like:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" version="1.0">
<xs:element name="root">
<xs:complexType>
<xs:attribute name="prop1" use="required">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="ABC"/>
<xs:enumeration value="XYZ"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="prop2"/>
<xs:attribute name="prop3"/>
</xs:complexType>
</xs:element>
</xs:schema>
> Or is the restriction too fine that it is to be handled within the
application?
No, you don't have to handle it in the application. Starting from that form,
you could annotate it with Schematron constraints to cover the cases you
need and use an xsd+Schematron validator. Can't help you with an example, as
I wouldn't do it that way.
How did I write the above? I'm glad you asked. ;-} What you want to do is
very easy to describe in RELAX NG. E.g., here it is in the concise syntax:
element root {
(attribute prop1 {"ABC"}, attribute prop2 {text})
| (attribute prop1 {"XYZ"}, attribute prop3 {text})}
(Which I wrote from your description as fast as I can type.) After checking
and testing this schema with jing, I converted it to xsd with trang.
Bob
|