W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2002

Re: Attribute Problem!!

From: Jeni Tennison <jeni@jenitennison.com>
Date: Thu, 11 Apr 2002 09:24:25 +0100
Message-ID: <31780650345.20020411092425@jenitennison.com>
To: czadra@geo.unizh.ch ((Cyrill Zadra))
CC: xmlschema-dev@w3.org
Hi Cyrill,

> I'd like to describe the following xml element with xml-schema!!
> <link url="...">
> But the problem is, that the element <link>  can also have the attribute
> mail ->
> <link mail="">
> <link refer=""> -> A Reference to an other point in the document!
> Does anybody know a solution for this in xml-schema??

You can say that the link element can have url, mail and refer
attributes easily enough:

<xs:element name="link">
    <xs:attribute name="url" type="xs:anyURI" />
    <xs:attribute name="mail" type="xs:string" />
    <xs:attribute name="refer" type="xs:IDREF" />

What's difficult (and I suspect the part that you're having problems
with) is stating that they must each have one and only one of those
attributes. In fact, it's impossible to do this in XML Schema. The
best thing to do is add an extra layer to your validation and use
Schematron to check the co-occurrence constraint:

  <sch:rule context="link">
    <sch:assert test="count(@url | @mail | @refer) = 1">
      <sch:name /> must have one and only one of the attributes 'url',
      'mail' or 'refer'.



Jeni Tennison
Received on Thursday, 11 April 2002 04:24:29 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:56 UTC