Maksim wrote:
Trying to find out a way how to restrict value of the element by name of an
element,
it might be not even possible, but anyhow.
Let's consider following snippet:
<xs:element name="tag1" type="xs:string" />
<xs:element name="tag2" type="xs:string" />
<xs:element name="tag3" type="xs:string" />
....
<xs:element name="fields">
<xs:complexType>
<xs:sequence>
<xs:element name="field" type="xs:NMTOKEN" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
what I need is, somehow restrict value of the field based on name of the
elements,
in other word following would be valid
<fields>
<field>tag1</field>
</fields>
but other would give me a validation error.
<fields>
<field>tag1</field>
<field>tag10</field>
</fields>
You might be able to define an enumeration of those tag names e.g.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<xs:simpleType name="fieldNames">
<xs:restriction base="xs:NCName">
<xs:enumeration value="tag1" />
<xs:enumeration value="tag2" />
<xs:enumeration value="tag3" />
</xs:restriction>
</xs:simpleType>
<xs:element name="fields">
<xs:complexType>
<xs:sequence>
<xs:element name="field" maxOccurs="unbounded" type="fieldNames" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
then you can validate instances like
<?xml version="1.0" encoding="UTF-8"?>
<fields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test2004102701Xsd.x ml">
<field>tag1</field>
<field>tag2</field>
<field>tag10</field>
</fields>
Note that I have used NCName instead of NMToken as the latter should
only be used for attribute values.
--
Martin Honnen
http://JavaScript.FAQTs.com/