Re: [XML Schema 1.1] [Summary] Five questions about openContent when used with a type and subtype

On 5 Jun 2009, at 11:44 , Costello, Roger L. wrote:

>
> Hi Folks,
>
> Here are five questions I have about openContent when used with a  
> type and subtype.
>
>
> QUESTION #1
>
> Consider this base type (with mode="interleave") and a subtype:
>
>    <complexType name="Publication" abstract="true">
>        <openContent mode="interleave">
>            <any />
>        </openContent>
>        <sequence>
>            <element name="Title" type="string" />
>            <element name="Author" type="string" />
>            <element name="Date" type="gYear"/>
>        </sequence>
>    </complexType>
>
>    <complexType name="BookPublication">
>        <complexContent>
>            <extension base="pub:Publication">
>                <sequence>
>                    <element name="ISBN" type="string"/>
>                    <element name="Publisher" type="string"/>
>                </sequence>
>            </extension>
>        </complexContent>
>    </complexType>
>
> Now I declare the <Book> element to be of type BookPublication:
>
>    <element name="Book" type="pub:BookPublication">
>
> In the instance document, can I insert extension elements around the  
> base type elements: Title, Author, Date? How about around the  
> subtype elements: ISBN, Publisher?
>
>    <Book>
>        <Title>My Life and Times</Title> <-- around here?
>        <Author>Paul McCartney</Author> <-- around here?
>        <Date>1998</Date> <-- around here?
>        <ISBN>1-56592-235-2</ISBN> <-- around here?
>        <Publisher>McMillin Publishing</Publisher> <-- around here?
>    </Book>

You can do anything you want; nothing in the XSD spec will
get in your way.

If you mean "can a valid instance of pub:BookPublication
have extension elements in these places?", then the answer
depends, I think, on whether there is a <defaultOpenContent>
element appearing as a child of the schema document, and
if so what its properties are.

(1) If there is no default open content, then since
BookPublication has no explicit statement about open
content, it inherits the {open content} property of
its base type, and valid instances of BookPublication
can have extension elements in the places you mention.

(2) If the enclosing schema document has a default open
content element, then I believe that section 3.4.2.3.3
Mapping Rules for Content Type Property of Complex Content
says that it is the schema-document-level open content
specification which applies here.  If the default open
content specified at schema-document-level has mode="none",
then BookPublication does not have open content.  Otherwise,
it has the open content wildcard specified in the
<defaultOpenContent> element.

It may feel a little surprising that the open content
specification of the base type does not override that of
the schema document.  That is to say, it did surprise me
a little, so I'm worried that there is some rule I have
overlooked here.  But if I'm reading the spec correctly,
the consequence is just that you have to remember that
the rules for open content say, in effect, that a locally
specified rule wins, then a rule specified at the
schema-document level, and then a rule inherited from the
base type.

>
>
>
> QUESTION #2
>
> Consider this base type (with mode="interleave") and subtype (with  
> mode="none"):
>
>    <complexType name="Publication" abstract="true">
>        <openContent mode="interleave">
>            <any />
>        </openContent>
>        <sequence>
>            <element name="Title" type="string" />
>            <element name="Author" type="string" />
>            <element name="Date" type="gYear"/>
>        </sequence>
>    </complexType>
>
>    <complexType name="BookPublication">
>        <complexContent>
>            <extension base="pub:Publication">
>                <openContent mode="none">
>                    <any />
>                </openContent>
>                <sequence>
>                    <element name="ISBN" type="string"/>
>                    <element name="Publisher" type="string"/>
>                </sequence>
>            </extension>
>        </complexContent>
>    </complexType>
>
> Now I declare the <Book> element to be of type BookPublication:
>
>    <element name="Book" type="pub:BookPublication">
>
> In the instance document, can I insert extension elements around the  
> base type elements: Title, Author, Date? How about around the  
> subtype elements: ISBN, Publisher?
>
>    <Book>
>        <Title>My Life and Times</Title> <-- around here?
>        <Author>Paul McCartney</Author> <-- around here?
>        <Date>1998</Date> <-- around here?
>        <ISBN>1-56592-235-2</ISBN> <-- around here?
>        <Publisher>McMillin Publishing</Publisher> <-- around here?
>    </Book>



>
> -- From Michael's latest message, 
> -- this is an invalid schema. Yes?

Yes.  The base type has open content with mode=interleave.
(For brevity, let's call the open content of the base type
B, and that of the extension E.)  And E.mode=none.

Clause 1.4.3.2.2.3 of Schema Component Constraint: Derivation
Valid (Extension), in section 3.4.6.2 Derivation Valid
(Extension) of Structures, says that one of the following
must be true:

   1 B does not exist.          // false
   2 E.mode = interleave.       // false
   3 B.mode = E.mode = suffix.  // false

So the derivation fails to satisfy a cascade of clauses.
Because it doesn't satisfy 1.4.3.2.2.3, it also doesn't
satisfy 1.4.3.2.2, which means (together with some
other things) that it doesn't satisfy 1.4.3.2,
which means it fails 1.4.3, which means it fails 1.4,
which means it fails to satisfy clause 1, which means
the derivation is not valid.


>
>
>
> QUESTION #3
>
> Consider this base type and subtype (with mode="interleave"):
>
>    <complexType name="Publication" abstract="true">
>        <sequence>
>            <element name="Title" type="string" />
>            <element name="Author" type="string" />
>            <element name="Date" type="gYear"/>
>        </sequence>
>    </complexType>
>
>    <complexType name="BookPublication">
>        <complexContent>
>            <extension base="pub:Publication">
>                <openContent mode="interleave">
>                    <any />
>                </openContent>
>                <sequence>
>                    <element name="ISBN" type="string"/>
>                    <element name="Publisher" type="string"/>
>                </sequence>
>            </extension>
>        </complexContent>
>    </complexType>
>
> Now I declare the <Book> element to be of type BookPublication:
>
>    <element name="Book" type="pub:BookPublication">
>
> In the instance document, can I insert extension elements around the  
> base type elements: Title, Author, Date? How about around the  
> subtype elements: ISBN, Publisher?
>
>    <Book>
>        <Title>My Life and Times</Title> <-- around here?
>        <Author>Paul McCartney</Author> <-- around here?
>        <Date>1998</Date> <-- around here?
>        <ISBN>1-56592-235-2</ISBN> <-- around here?
>        <Publisher>McMillin Publishing</Publisher> <-- around here?
>    </Book>

The complex type of BookPublication has open content with
mode = interleave.  You declared it so, and it is so.
In valid instances of that type, extension elements
may appear in any of the locations you mention.  The
openness is not restricted to elements not present in the
base type.

>
>
> QUESTION #4
>
> Consider this base type (mode="suffix") and subtype (with  
> mode="interleave"):
>
>    <complexType name="Publication" abstract="true">
>        <openContent mode="suffix">
>            <any />
>        </openContent>
>        <sequence>
>            <element name="Title" type="string" />
>            <element name="Author" type="string" />
>            <element name="Date" type="gYear"/>
>        </sequence>
>    </complexType>
>
>    <complexType name="BookPublication">
>        <complexContent>
>            <extension base="pub:Publication">
>                <openContent mode="interleave">
>                    <any />
>                </openContent>
>                <sequence>
>                    <element name="ISBN" type="string"/>
>                    <element name="Publisher" type="string"/>
>                </sequence>
>            </extension>
>        </complexContent>
>    </complexType>
>
> Now I declare the <Book> element to be of type BookPublication:
>
>    <element name="Book" type="pub:BookPublication">
>
> In the instance document, can I insert extension elements around the  
> base type elements: Title, Author, Date? How about around the  
> subtype elements: ISBN, Publisher?
>
>    <Book>
>        <Title>My Life and Times</Title> <-- around here?
>        <Author>Paul McCartney</Author> <-- around here?
>        <Date>1998</Date> <-- around here?
>        <ISBN>1-56592-235-2</ISBN> <-- around here?
>        <Publisher>McMillin Publishing</Publisher> <-- around here?
>    </Book>

Same as for question 4.  A type with mode=suffix can be
extended by a type with mode=interleave.  It is the mode
on the type you are using that matters, not the mode on
the types in its base-type chain.

>
>
> QUESTION #5
>
> Consider this base type (mode="interleave") and subtype (with  
> mode="suffix"):
>
>    <complexType name="Publication" abstract="true">
>        <openContent mode="interleave">
>            <any />
>        </openContent>
>        <sequence>
>            <element name="Title" type="string" />
>            <element name="Author" type="string" />
>            <element name="Date" type="gYear"/>
>        </sequence>
>    </complexType>
>
>    <complexType name="BookPublication">
>        <complexContent>
>            <extension base="pub:Publication">
>                <openContent mode="suffix">
>                    <any />
>                </openContent>
>                <sequence>
>                    <element name="ISBN" type="string"/>
>                    <element name="Publisher" type="string"/>
>                </sequence>
>            </extension>
>        </complexContent>
>    </complexType>
>
> Now I declare the <Book> element to be of type BookPublication:
>
>    <element name="Book" type="pub:BookPublication">
>
> In the instance document, can I insert extension elements around the  
> base type elements: Title, Author, Date? How about around the  
> subtype elements: ISBN, Publisher?
>
>    <Book>
>        <Title>My Life and Times</Title> <-- around here?
>        <Author>Paul McCartney</Author> <-- around here?
>        <Date>1998</Date> <-- around here?
>        <ISBN>1-56592-235-2</ISBN> <-- around here?
>        <Publisher>McMillin Publishing</Publisher> <-- around here?
>    </Book>

You can do anything you like.  Nothing in XSD will get
in your way, or declare the element invalid.  (The element
can't be validated, because the schema document does not
map to a conforming schema:  it violates the rules for
complex type extension, see above, question 2.

hth

-- 
****************************************************************
* C. M. Sperberg-McQueen, Black Mesa Technologies LLC
* http://www.blackmesatech.com
* http://cmsmcq.com/mib
* http://balisage.net
****************************************************************

Received on Saturday, 6 June 2009 19:19:44 UTC