Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Applying Restrictions to XML Attributes >Thread Next - Re: Applying Restrictions to XML Attributes Re: Applying Restrictions to XML AttributesTo: NULL Date: 2/1/2008 9:49:00 AM mnickel67@g... <mnickel67@g...> wrote in <f0461272-9799-42a5-a909-1673f42564c8@d...>: > 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 <Record> block 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</> | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
