W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2007

constraints on attributes as a validation check (ish)

From: Andy Harris <andy.harris@ukbiobank.ac.uk>
Date: Thu, 30 Aug 2007 11:10:14 +0100
Message-ID: <952B5328C5BED844AA7B6252D30474BF4A4626@ukbiobankex01.hq.ukbiobank.ac.uk>
To: <xmlschema-dev@w3.org>

I'm a bit of an XSD newbie...
 
I have a set of xml files structured thus:
<root>
    <row typ="g01">
        <r>content1a</r>
        <r>content1b</r>
    </row> 
    <row typ="g02">
        <r>content2a</r>
        <r>content2b</r>
    </row> 
    <row typ="g03">
        <r>content3a</r>
        <r>content3b</r>
    </row> 
    <row type="g05">
        <r>content4a</r>
        <r>content4b</r> 
        <r>content4c</r>
    </row>
</root>
 
I need to verify that each file contains one and one only row element of
typ="g04".
Row elements may occur in any order and more than once.
Here is the *broad form* of xsd that I am using:
 
 <xs:element name="root">
  <xs:complexType>
   <xs:choice>
    <xs:sequence>
     <xs:element name="row" type="rowOther" />
     <xs:element name="row" type="rowg05" minOccurs="1"/>
    </xs:sequence>
   </xs:choice>
  </xs:complexType>
 </xs:element>

 <xs:complexType name="rowg05" abstract="true">
  <xs:sequence>
   <xs:element name="r"/>
  </xs:sequence>
  <xs:attribute name="typ" use="required">
   <xs:simpleType>
    <xs:restriction base="xs:string">
     <xs:enumeration value="g05"/>
    </xs:restriction>
   </xs:simpleType>
  </xs:attribute>
 </xs:complexType>
 
 <xs:complexType name="rowOther" abstract="true">
  <xs:sequence>
   <xs:element name="r"/>
  </xs:sequence>
  <xs:attribute name="typ" use="required">
   <xs:simpleType>
    <xs:restriction base="xs:string">
     <xs:enumeration value="g01"/>
     <xs:enumeration value="g02"/>
     <xs:enumeration value="g03"/>
     <xs:enumeration value="g04"/>
     <!--excluded <xs:enumeration value="g05"/>-->
     <xs:enumeration value="g06"/>
    </xs:restriction>
   </xs:simpleType>
  </xs:attribute>
 </xs:complexType>

I have tried various combinations of <complexType>,
abstract/non-abstract elements and such to get a result, but keep
getting hung up on declaring a row element with different types.
 
Am I making a daft mistake?
Is this actually possible with XSD?
Should I be using a different toolset?
 
Thanks
 
Andy Harris 
UK Biobank
 


The information contained in this e-mail is confidential and solely for the intended addressee(s).  Unauthorised reproduction, disclosure, modification, and/or distribution of this e-mail may be unlawful.  If you have received this e-mail in error, please notify the sender immediately and delete it from your system.  The views expressed in this message do not necessarily reflect those of UK Biobank.

UK Biobank Limited is registered as a charity in England and Wales (number 1101332) and is a company limited by guarantee (incorporated in England and Wales, registered number 4978912).   It's registered office is at 1-2 Spectrum Way, Adswood, Stockport, Cheshire SK3 0SA.
Received on Thursday, 30 August 2007 17:31:25 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:15:00 GMT