Re: Attribute Problem!!

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:complexType>
    ...
    <xs:attribute name="url" type="xs:anyURI" />
    <xs:attribute name="mail" type="xs:string" />
    <xs:attribute name="refer" type="xs:IDREF" />
  </xs:complexType>
</xs:element>

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'.
    </sch:assert>
  </sch:rule>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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