Example of an identity constraint that is not applied to substitution elements?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Example of an identity constraint that is not applied to substitution elements?

Costello, Roger L.
Hi Folks,

In section 2.2.4.4 of the Structures specification it says:

    ... elements substitutable for E are required to
    have types derived from T, but are not required
    to enforce the identity constraints ... of E.

I am trying to construct an example to illustrate this. That is, I seek to construct an element that has identity constraints and has substitutable elements, and the identity constraints are not enforced on the substitution elements.

Here's what I tried:

A BookStore contains multiple Books and each Book has a Title, Author, Date, ISBN, and Publisher. xsd:key is used to constrain each ISBN  to be unique:
-----------------------------------------------------------------------------------
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                     targetNamespace="http://www.books.org"
                    xmlns="http://www.books.org"
                    xmlns:bk="http://www.books.org"
                    elementFormDefault="qualified">

    <xsd:element name="BookStore">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="Book" maxOccurs="unbounded">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="Title" type="xsd:string" />
                            <xsd:element name="Author" type="xsd:string" />
                            <xsd:element name="Date" type="xsd:string" />
                            <xsd:element ref="ISBN" />
                            <xsd:element name="Publisher" type="xsd:string" />
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
        <xsd:key name="PK">
            <xsd:selector xpath="bk:Book"/>
            <xsd:field xpath="bk:ISBN"/>
        </xsd:key>
    </xsd:element>

    <xsd:element name="ISBN" type="xsd:string" />
    <xsd:element name="ISBN-10" substitutionGroup="ISBN" />
    <xsd:element name="ISBN-13" substitutionGroup="ISBN" />

</xsd:schema>
-----------------------------------------------------------------------------------
Notice the xsd:key requires the ISBN element be unique.

Also notice that I declared ISBN globally, and declared ISBN-10 and ISBN-13 to be substitutable for ISBN.


Here is an instance document that has each ISBN value unique and is schema-valid:

<?xml version="1.0"?>
<BookStore xmlns="http://www.books.org"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation=
                                  "http://www.books.org
                                   BookStore.xsd">
        <Book>
                <Title>My Life and Times</Title>
                <Author>Paul McCartney</Author>
                <Date>1998</Date>
                <ISBN>1-56592-235-2</ISBN>
                <Publisher>McMillin Publishing</Publisher>
        </Book>
        <Book>
                <Title>Illusions The Adventures of a Reluctant Messiah</Title>
                <Author>Richard Bach</Author>
                <Date>1977</Date>
                <ISBN>0-440-34319-4</ISBN>
                <Publisher>Dell Publishing Co.</Publisher>
        </Book>
        <Book>
                <Title>The First and Last Freedom</Title>
                <Author>J. Krishnamurti</Author>
                <Date>1954</Date>
                <ISBN>0-06-064831-7</ISBN>
                <Publisher>Harper &amp; Row</Publisher>
        </Book>
</BookStore>

Here is the same instance document, except I appended a copy of the first book, replacing its ISBN element with an ISBN-10 element:

<?xml version="1.0"?>
<BookStore xmlns="http://www.books.org"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation=
                                  "http://www.books.org
                                   BookStore.xsd">
        <Book>
                <Title>My Life and Times</Title>
                <Author>Paul McCartney</Author>
                <Date>1998</Date>
                <ISBN>1-56592-235-2</ISBN>
                <Publisher>McMillin Publishing</Publisher>
        </Book>
        <Book>
                <Title>Illusions The Adventures of a Reluctant Messiah</Title>
                <Author>Richard Bach</Author>
                <Date>1977</Date>
                <ISBN>0-440-34319-4</ISBN>
                <Publisher>Dell Publishing Co.</Publisher>
        </Book>
        <Book>
                <Title>The First and Last Freedom</Title>
                <Author>J. Krishnamurti</Author>
                <Date>1954</Date>
                <ISBN>0-06-064831-7</ISBN>
                <Publisher>Harper &amp; Row</Publisher>
        </Book>
        <Book>
                <Title>My Life and Times</Title>
                <Author>Paul McCartney</Author>
                <Date>1998</Date>
                <ISBN-10>1-56592-235-2</ISBN-10>
                <Publisher>McMillin Publishing</Publisher>
        </Book>
</BookStore>

That generates this error,

           The field in constraint {PK} has no value.

That's not the problem that I am trying to illustrate.

I seek a way to use an ISBN-10 element, containing a value that duplicates one of the ISBN element values, and does NOT generate an error.

But how?

/Roger

Reply | Threaded
Open this post in threaded view
|

Re: Example of an identity constraint that is not applied to substitution elements?

Mukul Gandhi
Hi Roger,

On Fri, Jun 15, 2012 at 6:48 PM, Costello, Roger L. <[hidden email]> wrote:

> That generates this error,
>
>           The field in constraint {PK} has no value.
[1]

I believe, this error message is correct. In your example, the IDC
constraint "PK" is defined for element "BookStore" (and not at level
of ISBN, as it might be confusing some of us).

> I seek a way to use an ISBN-10 element, containing a value that duplicates one of the ISBN element values, and does NOT
> generate an error.

I think, this may not be possible the way, the schema you've provided
is written and we would get an error message as above [1].




--
Regards,
Mukul Gandhi