mn*******@gmail.com <mn*******@gmail.comwrote in
<f0**********************************@d70g2000hsb. googlegroups.com>:
I'm still learning, so apologies if this is trivial...
W3C's XML Schema Primer is a good, solid tutorial, if a bit
on the chewy side.
<Record>
<foo id="a">... </foo>
<foo id="b">....</foo>
<foo id="c">.....</foo>
</Record>
Is it possible to create an xsd file that enforces that
within the <Recordblock there exists exactly three foo
tags each containing a different id value (from the enum
a, b, and c )?
It is possible.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element ref="Record"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Record">
<xs:complexType>
<xs:sequence>
<xs:element ref="foo" minOccurs="3" maxOccurs="3"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="abc">
<xs:selector xpath="foo"/>
<xs:field xpath="@id"/>
</xs:unique>
</xs:element>
<xs:element name="foo">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute ref="id" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:attribute name="id">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(a|b|c)"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>
Note that the fact that it is, indeed, possible doesn't yet
mean it's a good idea. My knee-jerk reaction would be to
redefine foo as three separate elements (foo-a, foo-b,
foo-c or something). Keep your grammars as simple as
possible, or you'll be in for a nasty surpise when you run
into unavoidable limitations of XML Schemata.
--
<>There is no phenotype</>