RE: [XML Schema 1.1] Does defaultOpenContent allow me to add extension elements before and after the root element?

OpenContent affects the elements that are permitted within the content model
of a complex type.

If you start the schema validator in strict mode, then it will find there is
no element declaration for r:MyFavoriteBookStore and report it as invalid:
that's because at this stage it's not testing the element for conformance
against a specific type, it's simply looking for an element declaration
because validation has to start somewhere. On the other hand, if you start
in lax mode, then it will skip this element and look for element
declarations that match its children, which will work just fine.

In practice most schema validators I know of insist on starting in strict
mode, though the spec doesn't require it.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay  

> -----Original Message-----
> From: xmlschema-dev-request@w3.org 
> [mailto:xmlschema-dev-request@w3.org] On Behalf Of Costello, Roger L.
> Sent: 04 June 2009 20:49
> To: 'xmlschema-dev@w3.org'
> Subject: [XML Schema 1.1] Does defaultOpenContent allow me to 
> add extension elements before and after the root element?
> 
> 
> Hi Folks,
> 
> Consider this schema, which uses <defaultOpenContent> to make 
> the entire schema open:
> 
> <?xml version="1.0"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>            targetNamespace="http://www.books.org"
>            xmlns="http://www.books.org"
>            elementFormDefault="qualified">
> 
>     <xs:defaultOpenContent mode="interleave">
>         <xs:any />
>     </xs:defaultOpenContent>
> 
>     <xs:element name="BookStore">
>         <xs:complexType>
>             <xs:sequence>
>                 <xs:element name="Book" maxOccurs="unbounded">
>                     <xs:complexType>
>                         <xs:sequence>
>                             <xs:element name="Title" 
> type="xs:string"/>
>                             <xs:element name="Author" 
> type="xs:string" />
>                             <xs:element name="Date" type="xs:string"/>
>                             <xs:element name="ISBN" type="xs:string"/>
>                             <xs:element name="Publisher" 
> type="xs:string"/>
>                         </xs:sequence>
>                     </xs:complexType>
>                 </xs:element>
>             </xs:sequence>
>         </xs:complexType>
>     </xs:element>
> 
> </xs:schema>
> 
> 
> Can I add extension elements before and after the root 
> element (BookStore)?
> 
> 
> Is this instance document legal (I have wrapped the root 
> element with an extension element):
> 
> <?xml version="1.0"?>
> <r:MyFavoriteBookStore xmlns:r="http://www.bookrepository.org">
>     <BookStore xmlns="http://www.books.org">
>         <Book>
>                 <Title>My Life and Times</Title>
>                 <Author>Paul McCartney</Author>
>                 <Date>1998</Date>
>                 <ISBN>1-56592-235-2</ISBN>
>                 <Publisher>McMillin Publishing</Publisher>
>                 <r:Binding>Hardcover</r:Binding>
>         </Book>
>         <Book>
>                 <r:Size>5 x 7</r:Size>
>                 <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>
>                 <r:NumPages>299</r:NumPages>
>                 <Date>1954</Date>
>                 <ISBN>0-06-064831-7</ISBN>
>                 <Publisher>Harper &amp; Row</Publisher>
>         </Book>
>     </BookStore>
> </r:MyFavoriteBookStore>
> 
> /Roger

Received on Thursday, 4 June 2009 22:16:21 UTC