Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


constraints on attributes as a validation check (ish)

From: "Andy Harris" <andy.harris@---------.--.-->
To: <xmlschema-dev@--.--->
Date: 8/30/2007 12:10:00 PM
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.


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