[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: [XML Schema] Here's how to empower instance documentauthor

  • From: Timothy Cook <timothywayne.cook@gmail.com>
  • To: "Costello, Roger L." <costello@mitre.org>
  • Date: Sun, 14 Oct 2012 22:22:03 -0300

Re:  [XML Schema] Here's how to empower instance documentauthor
Thanks Roger.

I had not thought of that before.  Your examples bring some
interesting use cases to mind.

In fact this approach can be used not just for the root element, but
any element.  This *may* be very interesting in cases of language
translations.  Thoughts?

Cheers,
Tim

On Sun, Oct 14, 2012 at 9:58 AM, Costello, Roger L. <costello@mitre.org> wrote:
> Hi Folks,
>
> It is not necessary to declare a root element in your XML Schema. You can empower instance document authors to create their own root element. Here's how:
>
> 1. In the XML Schema create a complexType for the root element, but don't declare a root element.
>
> 2. Instance document authors create their own root element name. They add this attribute onto their root element: xsi:type
>
> This is a powerful technique. The XML Schema is versatile since it can be repurposed for different things by instance document authors.
>
> Example: Here is an XML Schema. Notice that there is no declaration of a root element, there is only a global complexType (Books):
>
> --------------------------------------------------
>                      Books.xsd
> --------------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
>     <xs:complexType name="Books">
>         <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:gYear"/>
>                         <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:schema>
>
> Now each instance document author can name the root element anything he wants. One person may name the root element BookStore. Another may name the root element Library. And a third may name the root element Inventory. And so forth.
>
> This ability to repurpose the XML Schema is powerful.
>
> Here is one instance document, where the root element is named BookStore:
>
> --------------------------------------------------
>                      BookStore.xml
> --------------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <BookStore xsi:type="Books"
>                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>
>   <Book>
>     <Title>My Life and Times</Title>
>     <Author>Paul McCartney</Author>
>     <Date>1998</Date>
>     <ISBN>1-56592-235-2</ISBN>
>     <Publisher>McMillan 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>
>
> /Roger
>
> _______________________________________________________________________
>
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
>
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>



-- 
============================================
Timothy Cook, MSc           +55 21 94711995
MLHIM http://www.mlhim.org
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
Skype ID == timothy.cook
Academic.Edu Profile: http://uff.academia.edu/TimothyCook


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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.