choice between two attributes (schema)

Hauke Fuhrmann

Usenet Archive
Joined
Jan 14, 2003
Messages
5
Reaction score
0
Hello,

i have to write a schema definition, where only the two elements are allowed as follows:

<name firstname="Martin" surname="Mustermann"/>
<name institution="Mustermann inc."/>

how do I express, that the element name needs exactly the attribute "institution" or the two attributes "firstname" and "surname"?

A choice construct does not work for attributes, so how do I do it?

Gruß,
Hauke
 

FC

Usenet Archive
Joined
May 14, 2003
Messages
41
Reaction score
0
"Hauke Fuhrmann" wrote:

Hello,

i have to write a schema definition, where only the two elements are allowed as follows:

<name firstname="Martin" surname="Mustermann"/>
<name institution="Mustermann inc."/>

how do I express, that the element name needs exactly the attribute "institution" or the two attributes "firstname" and "surname"?

A choice construct does not work for attributes, so how do I do it?
...

Hello there,
here is a compromise solution:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="NAME">

<xsd:complexType>

<xsd:attributeGroup ref="attrGroup"/>

</xsd:complexType>

<xsd:unique name="exclude_Institution_and_Surname">

<xsd:selector xpath="."/>

<xsd:field xpath="@INSTITUTION | @SURNAME"/>

</xsd:unique>

<xsd:unique name="exclude_Institution_and_Firstname">

<xsd:selector xpath="."/>

<xsd:field xpath="@INSTITUTION | @FIRSTNAME"/>

</xsd:unique>

</xsd:element>

<xsd:attributeGroup name="attrGroup">

<xsd:attribute name="INSTITUTION" type="xsd:string"/>

<xsd:attribute name="SURNAME" type="xsd:string"/>

<xsd:attribute name="FIRSTNAME" type="xsd:string"/>

</xsd:attributeGroup>

</xsd:schema>

Unfortunately I could not find a way to make SURNAME or FIRSTNAME mandatory when either of the two is present, but the exclusive constraint between INSTITUTION and SURNAME or INSTITUTION and FIRSTNAME works fine.

Bye,
Flavio
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
In article <bneb8i$riu$07$>,
Hauke Fuhrmann wrote:

% i have to write a schema definition, where only the two elements are % allowed as follows:
%
% <name firstname="Martin" surname="Mustermann"/>
% <name institution="Mustermann inc."/>
%
% how do I express, that the element name needs exactly the attribute % "institution" or the two attributes "firstname" and "surname"?

This can't be expressed with XML Schemas. It can be expressed with RELAX NG in case that's an option.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top