[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Question on id constraints

  • From: Jeni Tennison <mail@j...>
  • To: "Anderson, John" <John@B...>
  • Date: Mon, 23 Jul 2001 17:33:54 +0100

xs unique
Hi John,

> The spec says that the selector must involve the child axis. This
> imples that in the following example:
>
> <files>
>   <file>
>     <directoryid>
>     <fileid>
>     <filetype>
>   </file>
>   <file> . . . etc
>
> </files>
>
> I would not be able to specify a unique or key for <file> consisting
> of the combination of <directoryid> & <fileid>, since the selector
> must point to either one or the other of these, unless the key is
> specified in the parent <files>.

I'm a bit confused by your terminology. The key has to be specified in
the parent files element because of the scope of the key - nothing to
do with the combination of fields. You can work out the key that you
need in XML Schema by completing the following sentence: "All X
elements within the Y element have a unique combination of A, B and
C."

The X elements are the things that should have an ID. In your case
these are the file elements. The Y element is an element that holds
all the X elements, often but not always the document element. In your
case that's the files element. The A, B and C elements or attributes
are children of or attributes on the X element that can be used to
identify it. In your case that's directoryid and fileid.

Now, the xs:unique element always needs to go in the element
declaration for the Y element. In your case that's the element
declaration for the files element; you should have something like:

<xs:element name="files" type="filesType">
  <xs:unique name="file-directory-and-file">
    ...
  </xs:unique>
</xs:element>

The xs:unique element needs to hold a single xs:selector element. This
xs:selector element points from the Y element to the X elements. In
your case that points to the child file elements of the files element:

<xs:element name="files" type="filesType">
  <xs:unique name="file-directory-and-file">
    <xs:selector xpath="file" />
    ...
  </xs:unique>
</xs:element>

After the xs:selector come a number of xs:field elements, each of
which points from the X element to the A, B and C elements or
attributes. In your case, you need one for the directoryid child of
the file element, and another for the fileid child of the file
element:

<xs:element name="files" type="filesType">
  <xs:unique name="file-directory-and-file">
    <xs:selector xpath="file" />
    <xs:field xpath="directoryid" />
    <xs:field xpath="fileid" />
  </xs:unique>
</xs:element>

> Anyone know if this is correct? It seems a bit limiting since I
> can't then reuse that constraint in other contexts where <file> is
> used without redefining it.

You are right that you can't reuse the identity constraints in other
contexts, aside from through copy and paste or entities if you're
feeling brave. You also can't use identity constraints across
documents or use axes other than the child or attribute axes in the
xpaths. For example, if your source was:

<files>
  <directory>
    <directoryid>...</directoryid>
    <file>
       <fileid>...</fileid>
    </file>
    ...
  </directory>
  ...
</files>

Then you couldn't say that within the files element every file element
has a unique combination of fileid and parent directory's directoryid
(though this would only matter if you could have several directory
elements with the same directoryid).

I suspect that these things are just the wrong side of the 80/20 split
:(

Cheers,

Jeni

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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.