Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Applying Restrictions to XML Attributes

From: Pavel Lepin <p.lepin@-------.--->
To: 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</>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent