OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Portable Constraints

Hi Folks,

[Definition] Portable Constraints: the ability to take an element declaration, with all its constraints, out of one XML Schema and drop it into another XML Schema, with all its constraints intact.

Example: The value of Publisher depends on which book store it is contained within:

<?xml version="1.0"?>
<BookStore storename="Barnes and Noble">
                <Title>Don't Make Me Think</Title>
                <Author>Steve Krug</Author>
                <Publisher>New Riders</Publisher>

If the store is Barnes and Noble then valid Publishers are Wrox Press and New Riders.

If the store is Borders then valid Publishers are Norton Press and friendsofed.

Earlier we examined two approaches to expressing the constraint on Publisher:

1.  Position an <assert> element on the BookStore element declaration:

   Assert: Book/Publisher = ('Wrox Press', 'New Riders')

2. Position <alternative> elements in the Publisher element declaration:

   Alternative: if @storename='Barnes and Noble' then 
                    text() = ('Wrox Press', 'New Riders')
   Alternative: if @storename='Borders' then 
                    text() = ('Norton Press', 'friendsofed')

and on the root element declare a storename attribute "inheritable."

The disadvantage of both solutions is that Publisher is not portable. The first approach requires an ancestor element impose the constraint on Publisher. The second approach requires an ancestor element have an inheritable storename attribute. That "contextual stuff" will be lost when Publisher is moved to other XML Schemas.

How can we design Publisher to be portable?

Portability approach: add a storename attribute directly on Publisher:

<Publisher storename="Barnes and Noble">New Riders</Publisher>

The XML Schema declares the Publisher element like this:

<xs:element name="Publisher">
             <xs:extension base="xs:string">
                <xs:attribute name="storename" type="xs:string" />
                <xs:assert test="if (@storename = 'Barnes and Noble') then 
                                     text() = ('Wrox Press', 'New Riders')
                                 else if (@storename = 'Borders') then 
                                     text() = ('friendsofed', 'Norton Press')
                                 else false()"/>

Now the Publisher element is portable: all its constraints are positioned within its element declaration; the element declaration can be copied and dropped into other XML Schemas without dragging around a bunch of "contextual stuff."

What are your thoughts on this approach to designing portable elements? 

Is portability important? What other techniques can be used to facilitate portability?


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS