jamil@onepost.net wrote:
Quote:
Take a look at the following XML doc:
>
<main>
<a>
<element>123</element>
</a>
<b>
<element>abc</element>
</b>
<c>
<element>true</element>
</c>
</main>
>
With this document, is it possible to create an XSD schema with
restrictions for the element "element" depending on its ancestor?
>
/main/a/element must be an integer containing only three digits.
/main/b/element must be a string containing only three characters.
/main/c/element must be a boolean.
>
I can define this in a schema if the elements had different names, but
I do not see a way to do it with the same name of element.
|
As those 'element' elements are children of different elements (e.g.
'a', 'b', 'c') it should not be a problem:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="main">
<xs:complexType>
<xs:sequence>
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element name="element">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:totalDigits value="3"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="b">
<xs:complexType>
<xs:sequence>
<xs:element name="element">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="3"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="c">
<xs:complexType>
<xs:sequence>
<xs:element name="element" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
--
Martin Honnen
http://JavaScript.FAQTs.com/