Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Schema restrictions on objects and instances

Reply
Thread Tools

Schema restrictions on objects and instances

 
 
Victor
Guest
Posts: n/a
 
      05-12-2004
I have a Schema with some elements which are "types" or objects, and
some elements which correspond to instances of the types. How can I
specify that a <locationInstance> must have an attribute "type" which
equals any one of the "id" attributes of the <locationType>s?

--
Victor
CERN / NTNU
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      05-12-2004


Victor wrote:

> I have a Schema with some elements which are "types" or objects, and
> some elements which correspond to instances of the types. How can I
> specify that a <locationInstance> must have an attribute "type" which
> equals any one of the "id" attributes of the <locationType>s?


Have a look at ID/IDREF and key/keyref.

--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
 
Victor
Guest
Posts: n/a
 
      05-13-2004
Martin Honnen wrote:
>
>
> Victor wrote:
>
>> I have a Schema with some elements which are "types" or objects, and
>> some elements which correspond to instances of the types. How can I
>> specify that a <locationInstance> must have an attribute "type" which
>> equals any one of the "id" attributes of the <locationType>s?

>
>
> Have a look at ID/IDREF and key/keyref.


Thanks!

After a lot of looking around for working and well-explained examples, I
managed to get the following (in case someone is looking for something
similar):

<xsd:schema xmlnssd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="ImportData">
<xsd:complexType>
<xsd:sequence>
.. definitions of the "locationType" and "location" elements ..
</xsd:sequence>
</xsd:complexType>

<xsd:key name="locationTypeId">
<xsd:annotation>
<xsd:documentation>Within the whole data set, every location
type must have a unique ID attribute</xsd:documentation>
</xsd:annotation>
<xsd:selector xpath=".//locationType"/>
<xsd:field xpath="@id"/>
</xsd:key>

<xsd:key name="locationId">
<xsd:annotation>
<xsd:documentation>Within the whole data set, every location
must have a unique ID attribute</xsd:documentation>
</xsd:annotation>
<xsd:selector xpath=".//location"/>
<xsd:field xpath="@id"/>
</xsd:key>

<xsd:keyref name="locationIdRef" refer="locationTypeId">
<xsd:annotation>
<xsd:documentation>Locations must be of an existing
locationType</xsd:documentation>
</xsd:annotation>
<xsd:selector xpath=".//location"/>
<xsd:field xpath="@type"/>
</xsd:keyref>

.... The rest of the Schema ...

A few notes:

- <key> is basically the same as <unique>, except that the elements
and/or attributes referenced in the <field> XPath _has_ to exist, i.e.
they cannot be empty.

--
Victor
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Restrictions in XML Schema Paul Johnston XML 1 11-20-2006 07:38 PM
XML Schema: How to put restrictions on element names ruediger XML 0 05-06-2006 08:51 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
JAXB : expecting an automatical control in java source when restrictions are specified in XML schema Jean-Marie Condom Java 2 11-26-2004 09:19 AM
Schema: complexType restrictions Moth XML 2 08-05-2003 02:55 PM



Advertisments