SlideShare una empresa de Scribd logo
1 de 11
Descargar para leer sin conexión
Creating Extensible Content Models
Table of Contents
               Issue
               Definition
               Introduction
               Extensibility via Type Substitution
               Extensibility via the <any> Element
               Non-determinism and the <any> element
               Best Practice

Issue
What is Best Practice for creating extensible content models?

Definition
An element has an extensible content model if in instance documents the authors can extend the
contents of that element with additional elements beyond what was specified by the schema.

Introduction
             <xsd:element name= “Book”>
               <xsd:complexType>
                 <xsd:sequence>
                   <xsd:element name=“Title” type=“string”/>
                   <xsd:element name=“Author” type=“string”/>
                   <xsd:element name=“Date” type=“string”/>
                   <xsd:element name=“ISBN” type=“string”/>
                   <xsd:element name=“Publisher” type=“string”/>
                 </xsd:sequence>
               </xsd:complexType>
             </xsd:element>

This schema snippet dictates that in instance documents the <Book> elements must always be
comprised of exactly 5 elements <Title>, <Author>, <Date>, <ISBN>, and <Publisher>. For
example:

             <Book>
                 <Title>The First and Last Freedom</TItle>
                 <Author>J. Krishnamurti</Author>
                 <Date>1954</Date>
                 <ISBN>0-06-0064831-7</ISBN>
                 <Publisher>Harper &amp; Row</Publisher>
             </Book>

The schema specifies a fixed/static content model for the Book element. Book’s content must
rigidly conform to just the schema specification. Sometimes this rigidity is a good thing.
Sometimes we want to give our instance documents more flexibility.

                                               64
How do we design the schema so that Book’s content model is extensible? Below are two
methods for implementing extensible content models.

Extensibility via Type Substitution
Consider this version of the above schema, where Book’s content model has been defined using a
type definition:

            <xsd:complexType name=“BookType”>
              <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 name=“ISBN” type=“xsd:string”/>
                <xsd:element name=“Publisher” type=“xsd:string” />
              </xsd:sequence>
            </xsd:complexType>
            <xsd:element name=“BookCatalogue”>
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name=“Book” type=“BookType”
                         maxOccurs=“unbounded”/>
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>

Recall that via the mechanism of type substitutability, the contents of <Book> can be substituted
by any type that derives from BookType.


                                   <Book>
                                     -- content --
                                   </Book>
For example, if a type is created which derives from BookType:

            <xsd:complexType name=“BookTypePlusReviewer”>
              <xsd:complexContent>
                <xsd:extension base=“BookType” >
                  <xsd:sequence>
                    <xsd:element name=“Reviewer” type=“xsd:string”/>
                  </xsd:sequence>
                </xsd:extension>
              </xsd:complexContent>
            </xsd:complexType>




                                               65
then instance documents can create a <Book> element that contains a <Reviewer> element,
along with the other five elements:

               <Book xsi:type=“BookTypePlusReviewer”>
                  <Title>My Life and Times</Title>
                  <Author>Paul McCartney</Author>
                  <Date>1998</Date>
                  <ISBN>94303-12021-43892</ISBN>
                  <Publisher>McMillin Publishing</Publisher>
                  <Reviewer>Roger Costello</Reviewer>
               </Book>

Thus, Book’s content model has been extended with a new element (Reviewer)!

In this example, BookTypePlusReviewer has been defined within the same schema as BookType.
In general, however, this may not be the case. Other schemas can import/include the
BookCatalogue schema and define types which derive from BookType. Thus, the contents of
Book may be extended, without modifying the BookCatalogue schema, as we see on the next
page:


              Extend a Schema, without Touching it!
                                                                            xmlns=quot; http://www.publishing.orgquot;
        xmlns=quot; http://www.publishing.orgquot;
                                                                            <xsd:complexType name=quot;BookTypequot;>
                                                                               <xsd:sequence>
        <xsd:include schemaLocation=quot;BookCatalogue.xsdquot;/>                          <xsd:element name=quot;Titlequot; type=quot;xsd:stringquot;/>
                                                                                   <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/>
                                                                                   <xsd:element name=quot;Datequot; type=quot;xsd:yearquot;/>
                                                                                   <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/>
        <xsd:complexType name=quot;BookTypePlusReviewerquot;>
                                                                                   <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/>
           <xsd:complexContent>
                                                                               </xsd:sequence>
               <xsd:extension base=quot;BookTypequot; >
                                                                            </xsd:complexType>
                 <xsd:sequence>
                    <xsd:element name=quot;Reviewerquot; type=quot;xsd:stringquot;/>
                 </xsd:sequence>                                            <xsd:element Book type=quot;BookTypequot;/>
               </xsd:extension>
           </xsd:complexContent>
        </xsd:complexType>
                                                                                      BookCatalogue.xsd

                    MyTypeDefinitions.xsd


And here’s what an instance document would look like:




                                                                       66
xmlns=quot;http://www.publishing.orgquot;


        xsi:schemaLocation=quot;http://www.publishing.org
                            MyTypeDefinitions.xsdquot;



        <Book xsi:type=quot;BookTypePlusReviewerquot;>
                                                             We have type-substituted
              <Title>The First and Last Freedom</Title>
                                                             Book's content with the
              <Author>J. Krishnamurti</Author>
                                                             type specified in the new
              <Date>1954</Date>
                                                             schema. Thus, we have
              <ISBN>0-06-064831-7</ISBN>
                                                             extended BookCatalogue.xsd
              <Publisher>Harper &amp; Row</Publisher>
                                                             without touching it!
              <Reviewer>Roger L. Costello</Reviewer>
        </Book>


This type substitutability mechanism is a powerful extensibility mechanism. However, it suffers
from two problems:

Disadvantages:
Location Restricted Extensibility: The extensibility is restricted to appending elements onto the
end of the content model (after the <Publisher> element). What if we wanted to extend <Book>
by adding elements to the beginning (before <Title>), or in the middle, etc? We can’t do it with
this mechanism.

Unexpected Extensibility: If you look at the declaration for Book:

            <xsd:element name=“Book” type=“BookType”
                   maxOccurs=“unbounded”/>

and the definition for BookType:

            <xsd:complexType name=“BookType”>
              <xsd:sequence>
                <xsd:element name=“Title” type=“xsd:string”/>
                <xsd:element name=“Author” type=“xsd:string”/>
                <xsd:element name=“Date” type=“xsd:gYear”/>
                <xsd:element name=“ISBN” type=“xsd:string”/>
                <xsd:element name=“Publisher” type=“xsd:string”/>
              </xsd:sequence>
            </xsd:complexType>




                                               67
it is easy to be fooled into thinking that in instance documents the <Book> elements will always
contain just <Title>, <Author>, <Date>, <ISBN>, and <Publisher>. It is easy to forget that
someone could extend the content model using the type substitutability mechanism.
Extensibility is unexpected! Consequently, if you write a program to process BookCatalogue
instance documents, you may forget to take into account the fact that a <Book> element may
contain more than five children.

It would be nice if there was a way to explicitly flag places where extensibility may occur: “hey,
instance documents may extend <Book> at this point, so be sure to write your code taking this
possibility into account.” In addition, it would be nice if we could extend Book’s content model
at locations other than just the end ... The <any> element gives us these capabilities beautifully,
as is discussed in the next section.

Extensibility via the <any> Element
An <any> element may be inserted into a content model to enable instance documents to contain
additional elements. Here’s an example showing an <any> element at the end of Book’s content
model:

            <xsd:element name= “Book”>
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name=“Title” type=“string”/>
                  <xsd:element name=“Author” type=“string”/>
                  <xsd:element name=“Date” type=“string”/>
                  <xsd:element name=“ISBN” type=“string”/>
                  <xsd:element name=“Publisher” type=“string”/>
                  <xsd:any namespace=”##any” minOccurs=”0”/>
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>

“The content of Book is Title, Author, Date, ISBN, Publisher and then (optionally) any well-
formed element. The new element may come from any namespace.”

Note the <any> element may be inserted at any point, e.g., it could be inserted at the top, in the
middle, etc.




                                                 68
In this version of the schema it has been explicitly specified that after the <Publication> element
any well-formed XML element may occur and that XML element may come from any
namespace. For example, suppose that the instance document author discovers a schema,
containing a declaration for a Reviewer element:


                   <xsd:element name=quot;Reviewerquot;>
                      <xsd:complexType>
                          <xsd:sequence>
                             <xsd:element name=quot;Namequot;>
                                 <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name=quot;Firstquot; type=quot;xsd:stringquot;/>
                                        <xsd:element name=quot;Lastquot; type=quot;xsd:stringquot;/>
                                    </xsd:sequence>
                                 </xsd:complexType>
                             </xsd:element>
                          </xsd:sequence>
                      </xsd:complexType>
                   </xsd:element>



And suppose that for an instance document author it is important that, in addition to specifying
the Title, Author, Date, ISBN, and Publisher of each Book, he/she specify a Reviewer. Because
the schema has been designed with extensibility in mind, the instance document author can use
the Reviewer element in his/her BookCatalogue:


                   <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>
                         <rev:Reviewer>
                             <rev:Name>
                                 <rev:Last>Costello</rev:Last>
                                 <rev:First>Roger</rev:First>
                             </rev:Name>
                         </rev:Reviewer>
                   </Book>

The instance document author has enhanced the instance document with an element that the
schema designer may have never even envisioned. We have empowered the instance author with
a great deal of flexibility in creating the instance document. Wow!



                                                  69
An alternate schema design is to create a BookType (as we did above) and embed the <any>
element within the BookType:


              <xsd:element name=quot;Bookquot;>
                 <xsd:sequence>
                     <xsd:element name=quot;Titlequot; type=quot;xsd:stringquot;/>
                     <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/>
                     <xsd:element name=quot;Datequot; type=quot;xsd:yearquot;/>
                     <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/>
                     <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/>
                     <xsd:any namespace=quot;##anyquot; minOccurs=quot;0quot;/>
                 </xsd:sequence>
              </xsd:element>

and then declare Book of type BookType:

                     <xsd:element Book type=quot;BookTypequot;/>
However, then we are then back to the “unexpected extensibilityquot; problem. Namely, after the
<Publication> element any well-formed XML element may occur, and after that anything could
be present.

There is a way to control the extensibility and still use a type. We can add a block attribute to
Book:

           <xsd:element Book type=quot;BookTypequot; block=quot;#allquot;/>
The block attribute prohibits derived types from being used in Book’s content model. Thus, by
this method we have created a reusable component (BookType), and yet we still have control
over the extensibility.

With the <any> element we have complete control over where, and how much extensibility we
want to allow. For example, suppose that we want to enable there to be at most two new elements
at the top of Book’s content model. Here’s how to specify that using the <any> element:




                                                 70
<xsd:complexType name=quot;Bookquot;>
            <xsd:sequence>
                 <xsd:any namespace=quot;##otherquot; minOccurs=quot;0quot; maxOccurs=quot;2quot;/>
                 <xsd:element name=quot;Titlequot; type=quot;xsd:stringquot;/>
                 <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/>
                 <xsd:element name=quot;Datequot; type=quot;xsd:stringquot;/
                 <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/>
                 <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/>
            </xsd:sequence>
       </xsd:complexType>

Note how the <any> element has been placed at the top of the content model, and it has set
maxOccurs=“2quot;. Thus, in instance documents the <Book> content will always end with <Title>,
<Author>, <Date>, <ISBN>, and <Publisher>. Prior to that, two well-formed XML elements
may occur.

In summary:
• We can put the <any> element specifically “where” we desire extensibility.
• If we desire extensibility at multiple locations, we can insert multiple <any> elements.
• With maxOccurs we can specify “how much” extensibility we will allow.
Non-Determinism and the <any> element
In the above BookType definition we used an <any> element at the beginning of the content
model. We specified that the <any> element must come from an other namepace (i.e., it must not
be an element from the targetNamespace). If, instead, we had specified namespace=“##any” then
we would have gotten a “non-deterministic content model” error when validating an instance
document. Let’s see why.

A non-deterministic content model is one where, upon encountering an element in an instance
document, it is ambiguous which path was taken in the schema document. For example. Suppose
that we were to declare BookType using ##any, as follows:


      <xsd:complexType name=quot;Bookquot;>
           <xsd:sequence>
                <xsd:any namespace=quot;##anyquot; minOccurs=quot;0quot; maxOccurs=quot;2quot;/>
                <xsd:element name=quot;Titlequot; type=quot;xsd:stringquot;/>
                <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/>
                <xsd:element name=quot;Datequot; type=quot;xsd:stringquot;/
                <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/>
                <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/>
           </xsd:sequence>
      </xsd:complexType>


                                                71
And suppose that we have this (snippet of an) instance document:



            <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>

Let’s see what happens when a schema validator gets to the <Title> element in this instance
document. The schema validator must determine what this Title element declarationt this
corresponds to in the schema document. Do you see the ambiguity? There is no way no know,
without doing a look-ahead, whether the Title element comes from the <any> element, or comes
from the <xsd:element name=“Title” .../> declaration. This is a non-deterministic content model:
if your schema has a content model which would require a schema validator to “look-ahead” then
your schema is non-deterministic. Non-deterministic schemas are not allowed.

The solution in our example is to declare that the <any> element must come from an other
namespace, as was shown earlier. That works fine in this example where all the BookCatalogue
elements come from the targetNamespace, and the <any> element comes from a different
namespace. Suppose, however, that the BookCatalogue schema imported element declarations
from other namespaces. For example:


            <?xml version=quot;1.0quot;?>
            <xsd:schema ...
                   xmlns:bk=quot;http://www.books.comquot; …>
              <xsd:import namespace=quot;http://www.books.comquot;
                     schemaLocation=quot;Books.xsdquot;/>
              <xsd:complexType name=quot;Bookquot;>
                     <xsd:sequence>
                            <xsd:any namespace=quot;##otherquot; minOccurs=quot;0quot;/>
                            <xsd:element ref=quot;bk:Titlequot;/>
                            <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/>
                            <xsd:element name=quot;Datequot; type=quot;xsd:stringquot;/>
                            <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/>
                            <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/>
                     </xsd:sequence>
              </xsd:complexType>
            </xsd:schema>




                                              72
Now consider this instance document:

             <Book>
                 <bk:Title>The First and Last Freedom</bk:TItle>
                 <Author>J. Krishnamurti</Author>
                 <Date>1954</Date>
                 <ISBN>0-06-0064831-7</ISBN>
                 <Publisher>Harper &amp; Row</Publisher>
             </Book>

When a schema validator encounters bk:Title it will try to validate it against the appropriate
element declaration in the schema. But is this the Title refered to by the schema (i.e., in the http://
www.books.com namespace), or does this Title come from using the <any> element? It is
ambiguous, and consequently non-deterministic. Thus, this schema is also illegal.

As you can see, prohibiting non-deterministic content models makes the use of the <any>
element quite restricted. So, what do you do when you want to enable extensibility at arbitrary
locations? Answer: put in an optional <other> element and let its content be <any>. Here’s how
to do it:

                     <xsd:complexType name=quot;Bookquot;>
                          <xsd:sequence>
                               <xsd:element name=quot;otherquot; minOccurs=quot;0quot;>
                                   <xsd:any namespace=quot;##anyquot; maxOccurs=quot;2quot;/>
                               </xsd:element>
                               <xsd:element name=quot;Titlequot; type=quot;xsd:stringquot;/>
                               <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/>
                               <xsd:element name=quot;Datequot; type=quot;xsd:stringquot;/
                               <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/>
                               <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/>
                          </xsd:sequence>
                     </xsd:complexType>


Now, instance document authors have an explicit container element (<other>) in which to put
additional elements. This isn’t the most ideal solution, but it’s the best that we can do given the
rule that schemas may not have non-deterministic content models. Write to the XML Schema
working group and tell them that you want the prohibition of non-deterministic content models
revoked!

Best Practice
The <any> element is an enabling technology. It turns instance documents from static/rigid
structures into rich, dynamic, flexible data objects. It shifts focus from the schema designer to the
instance document author in terms of defining what data makes sense. It empowers instance
document authors with the ability to decide what data makes sense to him/her.

As a schema designer you need to recognize your limitations. You have no way of anticipating all
the varieties of data that an instance document author might need in creating an instance
document. Be smart enough to know that you’re not smart enough to anticipate all possible
needs! Design your schemas with flexibility built-in.

                                                  73
Definition: an open content schema is one that allows instance documents to contain additional
elements beyond what is declared in the schema. As we have seen, this may be achieved by using
the <any> (and <anyAttribute>) element in the schema.

Sprinkling <any> and <anyAttribute> elements liberally throughout your schema will yield
benefits in terms of how evolvable your schema is:

Enabling Schema Evolution using Open Content Schemas
In today’s rapidly changing market static schemas will be less commonplace, as the market
pushes schemas to quickly support new capabilities. For example, consider the cellphone
industry. Clearly, this is a rapidly evolving market. Any schema that the cellphone community
creates will soon become obsolete as hardware/software changes extend the cellphone
capabilities. For the cellphone community rapid evolution of a cellphone schema is not just a
nicety, the market demands it!

Suppose that the cellphone community gets together and creates a schema, cellphone.xsd.
Imagine that every week NOKIA sends out to the various vendors an instance document
(conforming to cellphone.xsd), detailing its current product set. Now suppose that a few months
after cellphone.xsd is agreed upon NOKIA makes some breakthroughs in their cellphones - they
create new memory, call, and display features, none of which are supported by cellphone.xsd. To
gain a market advantage NOKIA will want to get information about these new capabilities to its
vendors ASAP. Further, they will have little motivation to wait for the next meeting of the
cellphone community to consider upgrades to cellphone.xsd. They need results NOW. How does
open content help? That is described next.

Suppose that the cellphone schema is declared “openquot;. Immediately NOKIA can extend its
instance documents to incorporate data about the new features. How does this change impact the
vendor applications that receive the instance documents? The answer is - not at all. In the worst
case, the vendor’s application will simply skip over the new elements. More likely, however, the
vendors are showing the cellphone features in a list box and these new features will be
automatically captured with the other features. Let’s stop and think about what has been just
described Without modifying the cellphone schema and without touching the vendor’s
applications, information about the new NOKIA features has been instantly disseminated to the
marketplace! Open content in the cellphone schema is the enabler for this rapid dissemination.

Clearly some types of instance document extensions may require modification to the vendor’s
applications. Recognize, however, that thevendors are free to upgrade their applications in their
own time. The applications do not need to be upgraded before changes can be introduced into
instance documents. At the very worst, the vendor’s applications will simply skip over the
extensions. And, of course, those vendors do not need to upgrade in lock-step

To wrap up this example suppose that several months later the cellphone community reconvenes
to discuss enhancements to the schema. The new features that NOKIA first introduced into the
marketplace are then officially added into the schema. Thus completes the cycle. Changes to the
instance documents have driven the evolution of the schema.



                                                74

Más contenido relacionado

Destacado

Partes Microscopio B Logia Bis
Partes Microscopio B Logia BisPartes Microscopio B Logia Bis
Partes Microscopio B Logia Bischarorope
 
Still from production
Still from productionStill from production
Still from productionLaMerlot
 
business phone system
business phone systembusiness phone system
business phone systemjoe
 
Pensiunea Katharina cazare pensiuni bran
Pensiunea Katharina cazare pensiuni branPensiunea Katharina cazare pensiuni bran
Pensiunea Katharina cazare pensiuni branPensiunea Katharina
 
Donald Trump
Donald TrumpDonald Trump
Donald Trumpjoe
 
01. Group & Centre Performance
01. Group & Centre Performance01. Group & Centre Performance
01. Group & Centre PerformanceStephen Healy
 
Coaching Seminario
Coaching SeminarioCoaching Seminario
Coaching Seminarioguest54ecf
 
Critical Linkages - TNC presentation to ILC
Critical Linkages - TNC presentation to ILCCritical Linkages - TNC presentation to ILC
Critical Linkages - TNC presentation to ILCdfggis
 
Still from production
Still from productionStill from production
Still from productionLaMerlot
 
The complete advertising website
The complete advertising websiteThe complete advertising website
The complete advertising websiteguest880c6a
 
Still from production
Still from productionStill from production
Still from productionLaMerlot
 

Destacado (20)

Partes Microscopio B Logia Bis
Partes Microscopio B Logia BisPartes Microscopio B Logia Bis
Partes Microscopio B Logia Bis
 
DéJame Vivir
DéJame VivirDéJame Vivir
DéJame Vivir
 
Still from production
Still from productionStill from production
Still from production
 
Testpres
TestpresTestpres
Testpres
 
Quieres Componer Hip Hop
Quieres Componer Hip HopQuieres Componer Hip Hop
Quieres Componer Hip Hop
 
Noms Egipcis
Noms EgipcisNoms Egipcis
Noms Egipcis
 
business phone system
business phone systembusiness phone system
business phone system
 
Antarctica
AntarcticaAntarctica
Antarctica
 
As TICS
As TICSAs TICS
As TICS
 
Pensiunea Katharina cazare pensiuni bran
Pensiunea Katharina cazare pensiuni branPensiunea Katharina cazare pensiuni bran
Pensiunea Katharina cazare pensiuni bran
 
Cookies
CookiesCookies
Cookies
 
Donald Trump
Donald TrumpDonald Trump
Donald Trump
 
Hello Paul 3º
Hello Paul 3ºHello Paul 3º
Hello Paul 3º
 
01. Group & Centre Performance
01. Group & Centre Performance01. Group & Centre Performance
01. Group & Centre Performance
 
Coaching Seminario
Coaching SeminarioCoaching Seminario
Coaching Seminario
 
Critical Linkages - TNC presentation to ILC
Critical Linkages - TNC presentation to ILCCritical Linkages - TNC presentation to ILC
Critical Linkages - TNC presentation to ILC
 
Still from production
Still from productionStill from production
Still from production
 
XML Bible
XML BibleXML Bible
XML Bible
 
The complete advertising website
The complete advertising websiteThe complete advertising website
The complete advertising website
 
Still from production
Still from productionStill from production
Still from production
 

Similar a Extensible Content Models

Variable Content Containers
Variable Content ContainersVariable Content Containers
Variable Content ContainersLiquidHub
 
35 schemas
35 schemas35 schemas
35 schemasmavilym
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schemagauravashq
 
XML Schema
XML SchemaXML Schema
XML Schemayht4ever
 
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...phanleson
 
JSUG - TU Wien Castor Project by Lukas Lang
JSUG - TU Wien Castor Project by Lukas LangJSUG - TU Wien Castor Project by Lukas Lang
JSUG - TU Wien Castor Project by Lukas LangChristoph Pickl
 
C:\fakepath\xsl final
C:\fakepath\xsl finalC:\fakepath\xsl final
C:\fakepath\xsl finalshivpriya
 
IQPC Canada XML 2001: How to develop Syntax and XML Schema
IQPC Canada XML 2001: How to develop Syntax and XML SchemaIQPC Canada XML 2001: How to develop Syntax and XML Schema
IQPC Canada XML 2001: How to develop Syntax and XML SchemaTed Leung
 
Xml For Dummies Chapter 12 Handling Transformations With Xsl it-slideshares...
Xml For Dummies   Chapter 12 Handling Transformations With Xsl it-slideshares...Xml For Dummies   Chapter 12 Handling Transformations With Xsl it-slideshares...
Xml For Dummies Chapter 12 Handling Transformations With Xsl it-slideshares...phanleson
 
JWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAXJWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAXHilary Mason
 
Significant Characteristics In Planets Manfred Thaller
Significant Characteristics In Planets Manfred ThallerSignificant Characteristics In Planets Manfred Thaller
Significant Characteristics In Planets Manfred ThallerDigitalPreservationEurope
 

Similar a Extensible Content Models (20)

Variable Content Containers
Variable Content ContainersVariable Content Containers
Variable Content Containers
 
35 schemas
35 schemas35 schemas
35 schemas
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
XSD
XSDXSD
XSD
 
Embedded Metadata working group
Embedded Metadata working groupEmbedded Metadata working group
Embedded Metadata working group
 
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
 
JSUG - TU Wien Castor Project by Lukas Lang
JSUG - TU Wien Castor Project by Lukas LangJSUG - TU Wien Castor Project by Lukas Lang
JSUG - TU Wien Castor Project by Lukas Lang
 
C:\fakepath\xsl final
C:\fakepath\xsl finalC:\fakepath\xsl final
C:\fakepath\xsl final
 
SCDJWS 1. xml schema
SCDJWS 1. xml schemaSCDJWS 1. xml schema
SCDJWS 1. xml schema
 
HTML & CSS
HTML & CSSHTML & CSS
HTML & CSS
 
IQPC Canada XML 2001: How to develop Syntax and XML Schema
IQPC Canada XML 2001: How to develop Syntax and XML SchemaIQPC Canada XML 2001: How to develop Syntax and XML Schema
IQPC Canada XML 2001: How to develop Syntax and XML Schema
 
Xml For Dummies Chapter 12 Handling Transformations With Xsl it-slideshares...
Xml For Dummies   Chapter 12 Handling Transformations With Xsl it-slideshares...Xml For Dummies   Chapter 12 Handling Transformations With Xsl it-slideshares...
Xml For Dummies Chapter 12 Handling Transformations With Xsl it-slideshares...
 
Widgets Tools Keynote
Widgets Tools KeynoteWidgets Tools Keynote
Widgets Tools Keynote
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
 
JWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAXJWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAX
 
Significant Characteristics In Planets Manfred Thaller
Significant Characteristics In Planets Manfred ThallerSignificant Characteristics In Planets Manfred Thaller
Significant Characteristics In Planets Manfred Thaller
 
O9schema
O9schemaO9schema
O9schema
 
Schema
SchemaSchema
Schema
 

Más de LiquidHub

Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0LiquidHub
 
Sharepoint 2013 upgrade process
Sharepoint 2013 upgrade processSharepoint 2013 upgrade process
Sharepoint 2013 upgrade processLiquidHub
 
Share point 2013
Share point 2013Share point 2013
Share point 2013LiquidHub
 
Share point 2010-uiimprovements
Share point 2010-uiimprovementsShare point 2010-uiimprovements
Share point 2010-uiimprovementsLiquidHub
 
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2LiquidHub
 
Managing metadata in_share_point_2010
Managing metadata in_share_point_2010Managing metadata in_share_point_2010
Managing metadata in_share_point_2010LiquidHub
 
Fast search for share point
Fast search for share pointFast search for share point
Fast search for share pointLiquidHub
 
Simple Farm Server Deployment
Simple Farm Server DeploymentSimple Farm Server Deployment
Simple Farm Server DeploymentLiquidHub
 
Pre Install Databases
Pre Install DatabasesPre Install Databases
Pre Install DatabasesLiquidHub
 
Moss 2007 Deployment Detail
Moss 2007 Deployment DetailMoss 2007 Deployment Detail
Moss 2007 Deployment DetailLiquidHub
 
Moss 2007 Backup Strategies
Moss 2007 Backup StrategiesMoss 2007 Backup Strategies
Moss 2007 Backup StrategiesLiquidHub
 
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003LiquidHub
 
5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps5060 A 01 Demonstration Steps
5060 A 01 Demonstration StepsLiquidHub
 
Working With Infopath 2007
Working With Infopath 2007Working With Infopath 2007
Working With Infopath 2007LiquidHub
 
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature WalkthroughWhats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature WalkthroughLiquidHub
 
Overviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshOverviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshLiquidHub
 
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 RefreshOrganizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 RefreshLiquidHub
 

Más de LiquidHub (20)

Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0
 
Sharepoint 2013 upgrade process
Sharepoint 2013 upgrade processSharepoint 2013 upgrade process
Sharepoint 2013 upgrade process
 
Share point 2013
Share point 2013Share point 2013
Share point 2013
 
Share point 2010-uiimprovements
Share point 2010-uiimprovementsShare point 2010-uiimprovements
Share point 2010-uiimprovements
 
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
 
Managing metadata in_share_point_2010
Managing metadata in_share_point_2010Managing metadata in_share_point_2010
Managing metadata in_share_point_2010
 
Fast search for share point
Fast search for share pointFast search for share point
Fast search for share point
 
Simple Farm Server Deployment
Simple Farm Server DeploymentSimple Farm Server Deployment
Simple Farm Server Deployment
 
Pre Install Databases
Pre Install DatabasesPre Install Databases
Pre Install Databases
 
Moss 2007 Deployment Detail
Moss 2007 Deployment DetailMoss 2007 Deployment Detail
Moss 2007 Deployment Detail
 
Moss 2007 Backup Strategies
Moss 2007 Backup StrategiesMoss 2007 Backup Strategies
Moss 2007 Backup Strategies
 
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
 
Bdc Screens
Bdc ScreensBdc Screens
Bdc Screens
 
Bdc Screens
Bdc ScreensBdc Screens
Bdc Screens
 
5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps
 
5060 A 01
5060 A 015060 A 01
5060 A 01
 
Working With Infopath 2007
Working With Infopath 2007Working With Infopath 2007
Working With Infopath 2007
 
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature WalkthroughWhats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
 
Overviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshOverviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components Refresh
 
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 RefreshOrganizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
 

Último

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 

Último (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 

Extensible Content Models

  • 1. Creating Extensible Content Models Table of Contents Issue Definition Introduction Extensibility via Type Substitution Extensibility via the <any> Element Non-determinism and the <any> element Best Practice Issue What is Best Practice for creating extensible content models? Definition An element has an extensible content model if in instance documents the authors can extend the contents of that element with additional elements beyond what was specified by the schema. Introduction <xsd:element name= “Book”> <xsd:complexType> <xsd:sequence> <xsd:element name=“Title” type=“string”/> <xsd:element name=“Author” type=“string”/> <xsd:element name=“Date” type=“string”/> <xsd:element name=“ISBN” type=“string”/> <xsd:element name=“Publisher” type=“string”/> </xsd:sequence> </xsd:complexType> </xsd:element> This schema snippet dictates that in instance documents the <Book> elements must always be comprised of exactly 5 elements <Title>, <Author>, <Date>, <ISBN>, and <Publisher>. For example: <Book> <Title>The First and Last Freedom</TItle> <Author>J. Krishnamurti</Author> <Date>1954</Date> <ISBN>0-06-0064831-7</ISBN> <Publisher>Harper &amp; Row</Publisher> </Book> The schema specifies a fixed/static content model for the Book element. Book’s content must rigidly conform to just the schema specification. Sometimes this rigidity is a good thing. Sometimes we want to give our instance documents more flexibility. 64
  • 2. How do we design the schema so that Book’s content model is extensible? Below are two methods for implementing extensible content models. Extensibility via Type Substitution Consider this version of the above schema, where Book’s content model has been defined using a type definition: <xsd:complexType name=“BookType”> <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 name=“ISBN” type=“xsd:string”/> <xsd:element name=“Publisher” type=“xsd:string” /> </xsd:sequence> </xsd:complexType> <xsd:element name=“BookCatalogue”> <xsd:complexType> <xsd:sequence> <xsd:element name=“Book” type=“BookType” maxOccurs=“unbounded”/> </xsd:sequence> </xsd:complexType> </xsd:element> Recall that via the mechanism of type substitutability, the contents of <Book> can be substituted by any type that derives from BookType. <Book> -- content -- </Book> For example, if a type is created which derives from BookType: <xsd:complexType name=“BookTypePlusReviewer”> <xsd:complexContent> <xsd:extension base=“BookType” > <xsd:sequence> <xsd:element name=“Reviewer” type=“xsd:string”/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> 65
  • 3. then instance documents can create a <Book> element that contains a <Reviewer> element, along with the other five elements: <Book xsi:type=“BookTypePlusReviewer”> <Title>My Life and Times</Title> <Author>Paul McCartney</Author> <Date>1998</Date> <ISBN>94303-12021-43892</ISBN> <Publisher>McMillin Publishing</Publisher> <Reviewer>Roger Costello</Reviewer> </Book> Thus, Book’s content model has been extended with a new element (Reviewer)! In this example, BookTypePlusReviewer has been defined within the same schema as BookType. In general, however, this may not be the case. Other schemas can import/include the BookCatalogue schema and define types which derive from BookType. Thus, the contents of Book may be extended, without modifying the BookCatalogue schema, as we see on the next page: Extend a Schema, without Touching it! xmlns=quot; http://www.publishing.orgquot; xmlns=quot; http://www.publishing.orgquot; <xsd:complexType name=quot;BookTypequot;> <xsd:sequence> <xsd:include schemaLocation=quot;BookCatalogue.xsdquot;/> <xsd:element name=quot;Titlequot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Datequot; type=quot;xsd:yearquot;/> <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/> <xsd:complexType name=quot;BookTypePlusReviewerquot;> <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/> <xsd:complexContent> </xsd:sequence> <xsd:extension base=quot;BookTypequot; > </xsd:complexType> <xsd:sequence> <xsd:element name=quot;Reviewerquot; type=quot;xsd:stringquot;/> </xsd:sequence> <xsd:element Book type=quot;BookTypequot;/> </xsd:extension> </xsd:complexContent> </xsd:complexType> BookCatalogue.xsd MyTypeDefinitions.xsd And here’s what an instance document would look like: 66
  • 4. xmlns=quot;http://www.publishing.orgquot; xsi:schemaLocation=quot;http://www.publishing.org MyTypeDefinitions.xsdquot; <Book xsi:type=quot;BookTypePlusReviewerquot;> We have type-substituted <Title>The First and Last Freedom</Title> Book's content with the <Author>J. Krishnamurti</Author> type specified in the new <Date>1954</Date> schema. Thus, we have <ISBN>0-06-064831-7</ISBN> extended BookCatalogue.xsd <Publisher>Harper &amp; Row</Publisher> without touching it! <Reviewer>Roger L. Costello</Reviewer> </Book> This type substitutability mechanism is a powerful extensibility mechanism. However, it suffers from two problems: Disadvantages: Location Restricted Extensibility: The extensibility is restricted to appending elements onto the end of the content model (after the <Publisher> element). What if we wanted to extend <Book> by adding elements to the beginning (before <Title>), or in the middle, etc? We can’t do it with this mechanism. Unexpected Extensibility: If you look at the declaration for Book: <xsd:element name=“Book” type=“BookType” maxOccurs=“unbounded”/> and the definition for BookType: <xsd:complexType name=“BookType”> <xsd:sequence> <xsd:element name=“Title” type=“xsd:string”/> <xsd:element name=“Author” type=“xsd:string”/> <xsd:element name=“Date” type=“xsd:gYear”/> <xsd:element name=“ISBN” type=“xsd:string”/> <xsd:element name=“Publisher” type=“xsd:string”/> </xsd:sequence> </xsd:complexType> 67
  • 5. it is easy to be fooled into thinking that in instance documents the <Book> elements will always contain just <Title>, <Author>, <Date>, <ISBN>, and <Publisher>. It is easy to forget that someone could extend the content model using the type substitutability mechanism. Extensibility is unexpected! Consequently, if you write a program to process BookCatalogue instance documents, you may forget to take into account the fact that a <Book> element may contain more than five children. It would be nice if there was a way to explicitly flag places where extensibility may occur: “hey, instance documents may extend <Book> at this point, so be sure to write your code taking this possibility into account.” In addition, it would be nice if we could extend Book’s content model at locations other than just the end ... The <any> element gives us these capabilities beautifully, as is discussed in the next section. Extensibility via the <any> Element An <any> element may be inserted into a content model to enable instance documents to contain additional elements. Here’s an example showing an <any> element at the end of Book’s content model: <xsd:element name= “Book”> <xsd:complexType> <xsd:sequence> <xsd:element name=“Title” type=“string”/> <xsd:element name=“Author” type=“string”/> <xsd:element name=“Date” type=“string”/> <xsd:element name=“ISBN” type=“string”/> <xsd:element name=“Publisher” type=“string”/> <xsd:any namespace=”##any” minOccurs=”0”/> </xsd:sequence> </xsd:complexType> </xsd:element> “The content of Book is Title, Author, Date, ISBN, Publisher and then (optionally) any well- formed element. The new element may come from any namespace.” Note the <any> element may be inserted at any point, e.g., it could be inserted at the top, in the middle, etc. 68
  • 6. In this version of the schema it has been explicitly specified that after the <Publication> element any well-formed XML element may occur and that XML element may come from any namespace. For example, suppose that the instance document author discovers a schema, containing a declaration for a Reviewer element: <xsd:element name=quot;Reviewerquot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;Namequot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;Firstquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Lastquot; type=quot;xsd:stringquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> And suppose that for an instance document author it is important that, in addition to specifying the Title, Author, Date, ISBN, and Publisher of each Book, he/she specify a Reviewer. Because the schema has been designed with extensibility in mind, the instance document author can use the Reviewer element in his/her BookCatalogue: <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> <rev:Reviewer> <rev:Name> <rev:Last>Costello</rev:Last> <rev:First>Roger</rev:First> </rev:Name> </rev:Reviewer> </Book> The instance document author has enhanced the instance document with an element that the schema designer may have never even envisioned. We have empowered the instance author with a great deal of flexibility in creating the instance document. Wow! 69
  • 7. An alternate schema design is to create a BookType (as we did above) and embed the <any> element within the BookType: <xsd:element name=quot;Bookquot;> <xsd:sequence> <xsd:element name=quot;Titlequot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Datequot; type=quot;xsd:yearquot;/> <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/> <xsd:any namespace=quot;##anyquot; minOccurs=quot;0quot;/> </xsd:sequence> </xsd:element> and then declare Book of type BookType: <xsd:element Book type=quot;BookTypequot;/> However, then we are then back to the “unexpected extensibilityquot; problem. Namely, after the <Publication> element any well-formed XML element may occur, and after that anything could be present. There is a way to control the extensibility and still use a type. We can add a block attribute to Book: <xsd:element Book type=quot;BookTypequot; block=quot;#allquot;/> The block attribute prohibits derived types from being used in Book’s content model. Thus, by this method we have created a reusable component (BookType), and yet we still have control over the extensibility. With the <any> element we have complete control over where, and how much extensibility we want to allow. For example, suppose that we want to enable there to be at most two new elements at the top of Book’s content model. Here’s how to specify that using the <any> element: 70
  • 8. <xsd:complexType name=quot;Bookquot;> <xsd:sequence> <xsd:any namespace=quot;##otherquot; minOccurs=quot;0quot; maxOccurs=quot;2quot;/> <xsd:element name=quot;Titlequot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Datequot; type=quot;xsd:stringquot;/ <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/> </xsd:sequence> </xsd:complexType> Note how the <any> element has been placed at the top of the content model, and it has set maxOccurs=“2quot;. Thus, in instance documents the <Book> content will always end with <Title>, <Author>, <Date>, <ISBN>, and <Publisher>. Prior to that, two well-formed XML elements may occur. In summary: • We can put the <any> element specifically “where” we desire extensibility. • If we desire extensibility at multiple locations, we can insert multiple <any> elements. • With maxOccurs we can specify “how much” extensibility we will allow. Non-Determinism and the <any> element In the above BookType definition we used an <any> element at the beginning of the content model. We specified that the <any> element must come from an other namepace (i.e., it must not be an element from the targetNamespace). If, instead, we had specified namespace=“##any” then we would have gotten a “non-deterministic content model” error when validating an instance document. Let’s see why. A non-deterministic content model is one where, upon encountering an element in an instance document, it is ambiguous which path was taken in the schema document. For example. Suppose that we were to declare BookType using ##any, as follows: <xsd:complexType name=quot;Bookquot;> <xsd:sequence> <xsd:any namespace=quot;##anyquot; minOccurs=quot;0quot; maxOccurs=quot;2quot;/> <xsd:element name=quot;Titlequot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Datequot; type=quot;xsd:stringquot;/ <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/> </xsd:sequence> </xsd:complexType> 71
  • 9. And suppose that we have this (snippet of an) instance document: <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> Let’s see what happens when a schema validator gets to the <Title> element in this instance document. The schema validator must determine what this Title element declarationt this corresponds to in the schema document. Do you see the ambiguity? There is no way no know, without doing a look-ahead, whether the Title element comes from the <any> element, or comes from the <xsd:element name=“Title” .../> declaration. This is a non-deterministic content model: if your schema has a content model which would require a schema validator to “look-ahead” then your schema is non-deterministic. Non-deterministic schemas are not allowed. The solution in our example is to declare that the <any> element must come from an other namespace, as was shown earlier. That works fine in this example where all the BookCatalogue elements come from the targetNamespace, and the <any> element comes from a different namespace. Suppose, however, that the BookCatalogue schema imported element declarations from other namespaces. For example: <?xml version=quot;1.0quot;?> <xsd:schema ... xmlns:bk=quot;http://www.books.comquot; …> <xsd:import namespace=quot;http://www.books.comquot; schemaLocation=quot;Books.xsdquot;/> <xsd:complexType name=quot;Bookquot;> <xsd:sequence> <xsd:any namespace=quot;##otherquot; minOccurs=quot;0quot;/> <xsd:element ref=quot;bk:Titlequot;/> <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Datequot; type=quot;xsd:stringquot;/> <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/> </xsd:sequence> </xsd:complexType> </xsd:schema> 72
  • 10. Now consider this instance document: <Book> <bk:Title>The First and Last Freedom</bk:TItle> <Author>J. Krishnamurti</Author> <Date>1954</Date> <ISBN>0-06-0064831-7</ISBN> <Publisher>Harper &amp; Row</Publisher> </Book> When a schema validator encounters bk:Title it will try to validate it against the appropriate element declaration in the schema. But is this the Title refered to by the schema (i.e., in the http:// www.books.com namespace), or does this Title come from using the <any> element? It is ambiguous, and consequently non-deterministic. Thus, this schema is also illegal. As you can see, prohibiting non-deterministic content models makes the use of the <any> element quite restricted. So, what do you do when you want to enable extensibility at arbitrary locations? Answer: put in an optional <other> element and let its content be <any>. Here’s how to do it: <xsd:complexType name=quot;Bookquot;> <xsd:sequence> <xsd:element name=quot;otherquot; minOccurs=quot;0quot;> <xsd:any namespace=quot;##anyquot; maxOccurs=quot;2quot;/> </xsd:element> <xsd:element name=quot;Titlequot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Authorquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Datequot; type=quot;xsd:stringquot;/ <xsd:element name=quot;ISBNquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;Publisherquot; type=quot;xsd:stringquot;/> </xsd:sequence> </xsd:complexType> Now, instance document authors have an explicit container element (<other>) in which to put additional elements. This isn’t the most ideal solution, but it’s the best that we can do given the rule that schemas may not have non-deterministic content models. Write to the XML Schema working group and tell them that you want the prohibition of non-deterministic content models revoked! Best Practice The <any> element is an enabling technology. It turns instance documents from static/rigid structures into rich, dynamic, flexible data objects. It shifts focus from the schema designer to the instance document author in terms of defining what data makes sense. It empowers instance document authors with the ability to decide what data makes sense to him/her. As a schema designer you need to recognize your limitations. You have no way of anticipating all the varieties of data that an instance document author might need in creating an instance document. Be smart enough to know that you’re not smart enough to anticipate all possible needs! Design your schemas with flexibility built-in. 73
  • 11. Definition: an open content schema is one that allows instance documents to contain additional elements beyond what is declared in the schema. As we have seen, this may be achieved by using the <any> (and <anyAttribute>) element in the schema. Sprinkling <any> and <anyAttribute> elements liberally throughout your schema will yield benefits in terms of how evolvable your schema is: Enabling Schema Evolution using Open Content Schemas In today’s rapidly changing market static schemas will be less commonplace, as the market pushes schemas to quickly support new capabilities. For example, consider the cellphone industry. Clearly, this is a rapidly evolving market. Any schema that the cellphone community creates will soon become obsolete as hardware/software changes extend the cellphone capabilities. For the cellphone community rapid evolution of a cellphone schema is not just a nicety, the market demands it! Suppose that the cellphone community gets together and creates a schema, cellphone.xsd. Imagine that every week NOKIA sends out to the various vendors an instance document (conforming to cellphone.xsd), detailing its current product set. Now suppose that a few months after cellphone.xsd is agreed upon NOKIA makes some breakthroughs in their cellphones - they create new memory, call, and display features, none of which are supported by cellphone.xsd. To gain a market advantage NOKIA will want to get information about these new capabilities to its vendors ASAP. Further, they will have little motivation to wait for the next meeting of the cellphone community to consider upgrades to cellphone.xsd. They need results NOW. How does open content help? That is described next. Suppose that the cellphone schema is declared “openquot;. Immediately NOKIA can extend its instance documents to incorporate data about the new features. How does this change impact the vendor applications that receive the instance documents? The answer is - not at all. In the worst case, the vendor’s application will simply skip over the new elements. More likely, however, the vendors are showing the cellphone features in a list box and these new features will be automatically captured with the other features. Let’s stop and think about what has been just described Without modifying the cellphone schema and without touching the vendor’s applications, information about the new NOKIA features has been instantly disseminated to the marketplace! Open content in the cellphone schema is the enabler for this rapid dissemination. Clearly some types of instance document extensions may require modification to the vendor’s applications. Recognize, however, that thevendors are free to upgrade their applications in their own time. The applications do not need to be upgraded before changes can be introduced into instance documents. At the very worst, the vendor’s applications will simply skip over the extensions. And, of course, those vendors do not need to upgrade in lock-step To wrap up this example suppose that several months later the cellphone community reconvenes to discuss enhancements to the schema. The new features that NOKIA first introduced into the marketplace are then officially added into the schema. Thus completes the cycle. Changes to the instance documents have driven the evolution of the schema. 74