Title: Schemas
1Schemas
- Deitel XML chapter 7
- Peltzer, XML Language Mechanics and Applications
(Addison Wesley) Chapter 4 has much more on W3C
schemas
2Schemas vs DTD
- DTDs are inherited from SGML (Standard
Generalized Markup Language). - They cant be manipulated (searched or
transformed into another format, like HTML) the
way XML documents can, because DTDs are not XML. - Schemas are XML. XML documents conforming to
schema require validating parsers like DTDs do. - Schemas themselves conform to DTDs which are
bundled with the parser. - Repositories of existing DTDs and Schema are
available for download free.
3Schemas
- DTDs define document structure, not content, so
although - ltvaluegt5lt/valuegt contains legal PCDATA, it cant
be checked to insure the content is numeric. - Markup like
- ltvaluegtHello Boblt/valuegt would also be valid
PCDATA. The application using this XML document
would itself have to test if value were numeric
and take appropriate action if the test failed. - Schemas are XML documents conforming to DTDs and
must be validated to be processed. Schema do not
use EBNF but use XML syntax. - Schema can be manipulated (eg., searched, or
elements added or removed) as with any XML
document. - W3C XML Schema are not covered (much) in Deitels
book, only MS Schema. Many W3C examples of
schema are in Peltzer, XML Language Mechanics and
Applications (Addison Wesley)
4Schemas
- Schemas view xml docs as a collection of
datatypes - DTDs view xml docs as a single entitity
- W3C 2001 schema specification lists 44 datatypes.
- There are 19 primitive types and 25 built-in,
derived types. - User derived and built-in types are both defined
using the simpleType definitions, which restrict
the type of data that can appear as content for
an attribute value or text-only element. - A schema datatype has 3 components a value
space, a lexical space, a set of facets.
5Examples
- In ltbookgt learning XLM lt/bookgt the value space
and lexical space are both string. (the value
is the literal string learning XML and lexical
space is the type string). - In ltnumbergt123lt/numbergt the value space is a set
of literals (digits), the lexical representation
might be a specified number of digit chars.
6A simple schema for Author (saved as .xsd)
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
ema"gt - ltxselement name"Author"gt
- ltxsannotationgt
- ltxsdocumentationgt
- lt/xsdocumentationgt
- lt/xsannotationgt
- ltxscomplexTypegt
- ltxssequencegt
- ltxselement name"Name"
type"xsstring"/gt - ltxselement name"Address"
type"xsstring"/gt - ltxselement name"City"
type"xsstring"/gt - ltxselement name"State"
type"xsstring"/gt - ltxselement name"Zip" type"xsstring"/gt
- lt/xssequencegt
- lt/xscomplexTypegt
- lt/xselementgt
- lt/xsschemagt
7In validator
8And an instance of the Author schema
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltAuthorgt
- ltNamegtDwight Peltzerlt/Namegt
- ltAddressgtPo Box 555lt/Addressgt
- ltCitygtOyster Baylt/Citygt
- ltStategtNYlt/Stategt
- ltZipgt11771lt/Zipgt
- lt/Authorgt
9Elements make up XML documents
- in MS Schema, ElementType defines an element. It
contains attributes describing content, data
type, name and so on for this element. - MSXML (microsofts validating parser) is part of
IE5, and is needed to build MS Schema. - Element Schema is the root element for every MS
Schema document.
10facets
- Facets define the value space and properties for
a specified data type. They consist of two types
fundamental and non-fundamental facets. - fundamental facets define a type
- non-fundamental facets impose restrictions on
the type by limiting the range
11fundamental facets
- Equal allows comparison
- Ordered- allows words to be placed in a
predefined ordering - Bounded- allows a lower and upper limit to be
provided - Cardinality- defines numeric relationship between
occurrences of an entity (as in minOccurs0
maxOccursunbounded ) Recall, we used the
for this in DTDs. - Numeric a value can be classified as numeric or
nonnumeric as in numeric(valuetrue) or
numeric(valuefalse) - Examplewe might define isbn to consist of
exactly 10 digit chars - ltxssimpleType name isbnType
- ltxsrestriction basexsstringgt
- xspattern value0-910/gt
- lt/xsrestrictiongt
- lt/xssimpleTypegt
- Note- this is not precisely the way isbns are
defined, since the last character might be alpha
and provides a parity check
12Eurosup to 10 decimal digits and exactly 2
decimal places
- ltxselement name Eurosgt
- ltxssimpleType name EuroDollarType
- ltxsrestriction basedecimalgt
- ltxstotalDigits value10/gt
- ltxsfractionDigits value2/gt
- lt/xsrestrictiongt
- lt/xssimpleTypegt
- lt/xselementgt
- A document instance
- ltEurosgt55.63lt/Eurosgt
13Derived user types use simpleType definitions
and one of 3 methods restriction, list and Union
- Restriction uses one or more constraining facets
to restrict the value or lexical space for the
base type. A postal code might use - ltxsdsimpleType name zipTypegt
- ltxsdrestriction basexsdstringgt
- ltxsdpattern value 0-99/gt
- lt/xsdrestrictiongt
- lt/xsdsimpleTypegt
14Derived user types list
- List uses a predetermined itemType sequence of
attributes to derive a new type. A
whitespace-delimited list of decimal values for
some lottery might be - lt?xml version1.0?gt
- ltxsschema xmlnsxshttp//www.w3.org/2001/XMLSch
emagt - ltxssimpleType nameMyWinningNumbersgt
- ltxslist itemType namedecimal/gt
- lt/xssimpleTypegt
- lt/xsschemagt
- With a document instance of
- ltnumbers xsitypeMyWinningNumbersgt94 33 12
76lt/numbersgt
15Text version is not validated
16Derived user typesunion
- Union creates a datatype derived from more than
one base type. A number of basetypes participate
in the union. - ltxsdsimpleType nameUnionDemogt
- ltxsdunion memberTypesAType BType/gt
- lt/xsdsimpleTypegt
- Here the two types could be any base types. This
would enable using eg., string or int to define a
month as in - ltMonthgtJan Feb Marlt/Monthgt
- ltMonthgt1 2 3lt/Monthgt
17A complex type xsd (see next slide for discussion
of sequence)
- ltxscomplexTypegt
- ltxssequencegt
- ltxselement name"Author"
type"xsstring"/gt - ltxselement name"Name"
type"xsstring"/gt - ltxselement name"Address"
type"xsstring"/gt - ltxselement name"City"
type"xsstring"/gt - ltxselement name"State"
type"xsstring"/gt - ltxselement name"Zip" type"xsstring"/gt
- lt/xssequencegt
- lt/xscomplexTypegt
18Compositors
- Allow us to specify
- Sequential order of elements
- Choice of elements
- The ALL compositor allowing no restrictions for
order and selection - The previous slide used sequence.
19Choice
- We might use, as part of a schema
- ltxschoicegt
- ltxselement namecreditcard typexsstring/gt
- ltxselement namecash typexsdecimal/gt
- ltxselement nametrade typexsstring/gt
- ltxschoicegt
20ALL
- ALL is similar to ANY
- ltxselement name"FamilyName"gt
- ltxscomplexTypegt
- ltxsallgt
- lt xselement name"firstName"
type"xsstring"/gt - ltxselement name"middleName"
type"xsstring"/gt - ltxselement name"lastName" type"xsstring"
minOccurs"0"/gt - lt/xsallgt
- lt/xscomplexTypegt
- lt/xselementgt
21namespaces
- Xsd and xs are used interchangeably.
- Xs serves as the default prefix for all XSD
schemas. - There are 3 distinct namespaces
- The XML schema namespace
- The XML schema data type namespace
- The XML schema instance namespace
- An example of the first appeared above as
- ltxsschema xmlnsxshttp//www.w3.org/2001/XMLSche
magt
22Global elements- anything declared before
complexType is global (see below)
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
ema" gt - ltxselement name"Name" type"xsstring"/gt
- ltxselement name"Address"
type"xsstring"/gt - ltxselement name"Author"gt
- lt!- -this is where global declarations stop - -gt
- ltxscomplexTypegt
- ltxssequencegt
- ltxselement name"City"
type"xsstring"/gt - ltxselement name"State"
type"xsstring"/gt - lt/xssequencegt
- lt/xscomplexTypegt
- lt/xselementgt
- lt/xsschemagt
23Global elements-document instance
- ltAuthor
- xmlnsxsi"http//www.w3.org/2001/XMLSchema-
instance" - xsinoNamespaceSchemaLocation"global.xsd"gt
- ltCitygtStringlt/Citygt
- ltStategtStringlt/Stategt
- lt/Authorgt
24Using a target namespace for your document ---
this binds the document to the schema
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltAuthor xmlnsxs"http//employees.oneonta.edu/hig
gindm/Authors"gt - ltNamegtDwight Peltzerlt/Namegt
- ltAddressgtPO Box 555lt/Addressgt
- ltCitygtOyster Baylt/Citygt
- ltStategtNYlt/Stategt
- ltZipgt11771lt/Zipgt
- ltPublishergt
- ltNamegtAddison Wesleylt/Namegt
- ltCitygtBostonlt/Citygt
- ltStategtMassachusettslt/Stategt
- lt/Publishergt
- ltBookTitlegtXML Language Mechanicslt/BookTitlegt
- ltISBNgt0-1-23458-0lt/ISBNgt
- lt/Authorgt
25target namespace for your document may be
omitted.
- This means you are using built-in types and
mapping all elements/attributes to the default
namespace. You are then prevented from reusing
locally declared elements. - lt?xml version"1.0" encoding"UTF-8"?gt
- ltxsschema xmlnsxshttp//www.w3.org/2001/XMLSch
emagt - ltxselement name"Author"gt
- ltxscomplexTypegt
- ltxssequencegt
- ltxselement name"Name"
type"xsstring"/gt - ltxselement name"Address"
type"xsstring"/gt - ltxselement name"City"
type"xsstring"/gt - ltxselement name"State"
type"xsstring"/gt - ltxselement name"Zip"
type"xsshort"/gt - ltxselement name"Publisher"
type"xsstring"/gt - ltxselement name"BookTitle"
type"xsstring"/gt - ltxselement name"ISBN"
type"xsstring"/gt - lt/xssequencegt
- lt/xscomplexTypegt
- lt/xselementgt
- lt/xsschemagt
26In validator
27The document instance would not then have a
namespace
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltAuthor
- xmlnsxsihttp//www.w3.org.2001.XMLSchema-i
nstance" - xsinoNamespaceSchemaLocation"Author.xsd"gt
- ltNamegtDwight Peltzerlt/Namegt
- ltAddressgtPO Box 555lt/Addressgt
- ltCitygtOyster Baylt/Citygt
- ltStategtNYlt/Stategt
- ltZipgt11771lt/Zipgt
- ltPublishergt
- ltNamegtAddison Wesleylt/Namegt
- ltCitygtBostonlt/Citygt
- ltStategtMassachusettslt/Stategt
- lt/Publishergt
- ltBookTitlegtXML Language Mechanicslt/BookTitlegt
- ltISBNgt0-1-23458-0lt/ISBNgt
- lt/Authorgt
28Adding the target namespace to the schema root
defines a namespace for your user-defined
declarations
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
ema" - targetNamespace"http//www.dpsoftware.com/name
spaces/Author" - xmlns"http//www.dpsoftware.com/namespaces/Aut
hor"gt - ltxselement name"Author"gt
- ltxscomplexTypegt
- ltxssequencegt
- ltxselement name"Name"
type"xsstring"/gt - ltxselement name"Address"
type"xsstring"/gt - ltxselement name"City"
type"xsstring"/gt - ltxselement name"State"
type"xsstring"/gt - ltxselement name"Zip"
type"xsstring"/gt - ltxselement name"Publisher"
type"xsstring"/gt - ltxselement name"BookTitle"
type"xsstring"/gt - ltxselement name"ISBN"
type"xsstring"/gt - lt/xssequencegt
- lt/xscomplexTypegt
- lt/xselementgt
- lt/xsschemagt
29An example document
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltdpAuthor
- xmlnsdp"http//www.dpsoftware.com/namespaces
/Author" - xmlnsxsi"http//www.w3.org/20011/XMLSchema-i
nstance" - xsischemaLocation"http//www.dpsoftware.com/
namespaces/author/AuthorV1.xsd"gt - ltNamegtDwight Peltzerlt/Namegt
- ltAddressgtPo Box 555lt/Addressgt
- ltCitygtOyster Baylt/Citygt
- ltStategtNYlt/Stategt
- ltZipgt11771lt/Zipgt
- ltPublishergtAddison Wesleylt/Publishergt
- ltBookTitlegtXML Language Mechanicslt/BookTitlegt
- ltISBNgt0-1-23458-0lt/ISBNgt
- lt/dpAuthorgt
30W\internet programming\validate_js.htm
31Namespace prefix can be used to qualify each
element in a doc
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltdpAuthor
- xmlnsdp"http//www.dpsoftware.com/namespace
s/author" - xmlnsxsi"http//www.w3.org/2001/XMLSchema-i
nstance" - xsiSchemaLocation"http//www.dpsoftware.com
/namespaces/author Author.xsd"gt - ltdpNamegtDwight Peltzerlt/dpNamegt
- ltdpAddressgtPO Box 555lt/dpAddressgt
- ltdpCitygtOyster Baylt/dpCitygt
- ltdpStategtNYlt/dpStategt
- ltdpZipgt11771lt/dpZipgt
- ltdpBookTitlegtXML Language
Mechanicslt/dpBookTitlegt - ltdpISBNgt0-1-23458-0lt/dpISBNgt
- lt/dpAuthorgt
32Russian doll model
- ltBookgt
- ltTitlegtXMLlt/Titlegt
- ltAuthorgtDwight Peltzerlt/Authorgt
- lt/Bookgt
- ltxsschema xmlnsxshttp//www.w3.org/2001/XMLSche
magt - ltxselement name"Book"gt
- ltxscomplexTypegt
- ltxssequencegt
- ltxselement name"Title"
type"xsstring"/gt - ltxselement name"Author"
type"xsstring"/gt - lt/xssequencegt
- lt/xscomplexTypegt
- lt/xselementgt
- lt/xsschemagt
33Salami slice model
- ltxselement name"Title" type"xsstring"/gt
- ltxselement name"Author" type"xsstring"/gt
- ltxselement name"Book"gt
- ltxscomplexTypegt
- ltxssequencegtltxsschema
xmlnsxs"http//www.w3.org/2001/XMLSchema"
elementFormDefault"qualified"gt - ltxselement name"Title" type"xsstring"/gt
- ltxselement name"Author" type"xsstring"/gt
- ltxselement name"Book"gt
- ltxscomplexTypegt
- ltxssequencegt
- ltxselement ref"Title"/gt
- ltxselement ref"Author"/gt
- lt/xssequencegt
- lt/xscomplexTypegt
- lt/xselementgt
- lt/xsschemagt
- lt!- -reassemble Title and Author - -gt
- ltxselement ref"Title"/gt
- ltxselement ref"Author"/gt
34Venetian blind model
- Venetian blind model uses elementFormDefault and
attributeFormDefault to switch back and forth
(hiding/exposing namespaces) in the document
instance - lt?xml version"1.0" encoding"UTF-8"?gt
- ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
ema" elementFormDefault"qualified"
attributeFormDefault"unqualified"gt - ltxselement name"Employer"gt
- ltxsannotationgt
- ltxsdocumentationgtComment describing your
root elementlt/xsdocumentationgt - lt/xsannotationgt
- lt/xselementgt
- ltxscomplexType name"employeeType"gt
- ltxssequencegt
- ltxselement name"name"
type"xsstring"/gt - ltxselement name"contact"
type"xsstring"/gt - lt/xssequencegt
- lt/xscomplexTypegt
- ltxscomplexType name"employeeTypeExt"gt
- ltxscomplexContentgt
- ltxsextension base"employeeType"gt
- ltxssequencegt
- ltxselement name"empName"
type"employeeType"/gt
35All NamedType components in this xsd are reusable
- ltxssimpleType name"Title"gt
- ltxsrestriction base"xsstring"gt
- ltxsenumeration value"Sci_Fi"/gt
- ltxsenumeration value"Information
Systems"/gt - lt/xsrestrictiongt
- lt/xssimpleTypegt
- ltxssimpleType name"Name"gt
- ltxsrestriction base"xsstring"gt
- ltxsminLength value"1"/gt
- lt/xsrestrictiongt
- lt/xssimpleTypegt
- ltxscomplexType name"Editor"gt
- ltxssequencegt
- ltxselement name"Title" type"Title"/gt
- ltxselement name"Author" type"Editor"/gt
- lt/xscomplexTypegt
- ltxselement name"Book" type"Editor"/gt
36ContentModel template- use type attribute to
reference the named complex type definition
- ltxscomplexType name"nameType"gt
- ltxssequencegt
- ltxselement ref"firstName"/gt
- ltxselement ref"middleName"/gt
- ltxselement ref"lastName"/gt
- lt/xssequencegt
- /xscomplexTypegt
37An ms schema
- lt?xml version "1.0"?gt
- lt!-- intro-schema.xml --gt
- lt!-- Microsoft XML Schema showing the ElementType
--gt - ltSchema xmlns "urnschemas-microsoft-comxml-dat
a"gt - ltElementType name "message" content
"textOnly" - model "closed"gt
- ltdescriptiongtText messageslt/descriptiongt
- lt/ElementTypegt
- ltElementType name "greeting" model
"closed" - content "mixed" order "many"gt
- ltelement type "message"/gt
- lt/ElementTypegt
- ltElementType name "myMessage" model
"closed" - content "eltOnly" order "seq"gt
- ltelement type "greeting" minOccurs "0"
- maxOccurs "1"/gt
- ltelement type "message" minOccurs "1"
- maxOccurs ""/gt
- lt/ElementTypegt
38schema elements
- xmlns specifies the default namespace for the
Schema element and the elements it contains. - Attribute value urn... is the uri for this
namespace. - Microsofts xml parser recognizes element Schema
and this namespace and validates the schema. - Element Schema can contain only elements of
ElementType for defining elements, AttributeType
for their attributes and description for
describing the element. - This example specifies that element message may
contain textOnly. - The closed model attribute specifies that only
elements declared in this schema may appear in
conforming xml documents, anything else would
invalidate the document. - Element greeting has mixed content, indicating
that both elements and character data may appear
here. Order many indicates that any number of
message elements and text may be contained in the
greeting.
39a conforming xml document
- lt?xml version "1.0"?gt
- lt!-- Fig. 7.2 intro.xml --gt
- lt!-- Introduction to Microsoft XML Schema --gt
- ltmyMessage xmlns "x-schemaintro-schema.xml"gt
- ltgreetinggtWelcome to XML Schema!
- ltmessagegtThis is the first
message.lt/messagegt - lt/greetinggt
- ltmessagegtThis is the second message.lt/messagegt
- lt/myMessagegt
40msxml validator
41a well-formed but non-conforming xml document
- lt?xml version "1.0"?gt
- lt!-- Fig. 7.3 intro2.xml --gt
- lt!-- An invalid document --gt
- ltmyMessage xmlns "x-schemaintro-schema.xml"gt
- ltgreetinggtWelcome to XML Schema!lt/greetinggt
- ltmessagegtThis is a message that contains
another message. - ltmessagegtThis is the inner
message.lt/messagegt - lt/messagegt
- lt/myMessagegt
42using validator
43Namespaces and declaring schema
- ltmyMessage xmlns "x-schemaintro-schema.xml"gt
- The namespace declaration xmlns references
the schema being used. - For MS Schema, the URI must begin with x-schema
followed by a colon and the name of the schema
document. - Element greeting may have mixed content and in
this example greeting marks up text and has a
child message element.
44Element attributes
- ElementType has attributes content, dttype,
name, model and order. - Element ElementTypes child elements are
description, datatype, element, group,
AttributeType and attribute. - Element element has attributes type, minOccurs,
maxOccurs. - Element group has attributes order, minOccurs,
maxOccurs. - Element AttributeType has attributes default,
dttype, dtvalues, name and required. - Element attribute has attributes default, type,
required.
45An example of AttributeType and attribute
- lt?xml version "1.0"?gt
- lt!-- contact-schema.xml --gt
- lt!-- Defining attributes --gt
- ltSchema xmlns "urnschemas-microsoft-comxml-dat
a"gt - ltElementType name "contact" content
"eltOnly" order "seq" - model "closed"gt
- ltAttributeType name "owner" required
"yes"/gt - ltattribute type "owner"/gt
- ltelement type "name"/gt
- ltelement type "address1"/gt
- ltelement type "address2" minOccurs "0"
maxOccurs "1"/gt - ltelement type "city"/gt
- ltelement type "state"/gt
- ltelement type "zip"/gt
- ltelement type "phone" minOccurs "0"
maxOccurs ""/gt - lt/ElementTypegt
-
46An example of AttributeType and attribute (part2)
- ltElementType name "name" content "textOnly"
- model "closed"/gt
- ltElementType name "address1" content
"textOnly" - model "closed"/gt
- ltElementType name "address2" content
"textOnly" - model "closed"/gt
- ltElementType name "city" content
"textOnly" - model "closed"/gt
- ltElementType name "state" content
"textOnly" - model "closed"/gt
- ltElementType name "zip" content "textOnly"
model "closed"/gt - ltElementType name "phone" content
"textOnly" model "closed"gt - ltAttributeType name "location" default
"home"/gt - ltattribute type "location"/gt
- lt/ElementTypegt
- lt/Schemagt
47A conforming xml document
- lt?xml version "1.0"?gt
- lt!-- Fig. 7.11 contact.xml --gt
- lt!-- A contact list marked up as XML --gt
- ltcontact owner "Bob Smith" xmlns
"x-schemacontact-schema.xml"gt - ltnamegtJane Doelt/namegt
- ltaddress1gt123 Main St.lt/address1gt
- ltcitygtSometownlt/citygt
- ltstategtSomestatelt/stategt
- ltzipgt12345lt/zipgt
- ltphonegt617-555-1234lt/phonegt
- ltphone location "work"gt978-555-4321lt/phonegt
- lt/contactgt
48Contact.xml in validator
49MS Schema datatypes
- DTD did not permit the specification of allowable
datatypes (content) an element or attribute might
contain. - Namespace prefix dt is defined by the document
author and assigned to urnschemas-microsoft-comd
atatypes - Msdn.microsoft.com/xml/reference/schema/datatypes.
asp has a complete list of types supported.
50MS Schema datatypes
- boolean 0 or 1
- char a character, X
- string a sequence of char as in XYZ
- float and int as in C or Java
- date YYYY-MM-DD
- timeHHMMSS
- id text which uniquely identifies an element or
its attribute. - idref a reference to an id.
- enumeration a series of values from which one is
chosen.
51using data types
- lt?xml version "1.0"?gt
- lt!-- Fig. 7.13 id-schema.xml --gt
- lt!-- Using datatype ID --gt
- ltSchema xmlns "urnschemas-microsoft-comxml-dat
a" - xmlnsdt "urnschemas-microsoft-comdata
types"gt - ltElementType name "bookstore" content
"eltOnly" - order "many" model "closed"gt
- ltelement type "shipping"/gt
- ltelement type "book"/gt
- lt/ElementTypegt
- ltElementType name "shipping" content
"eltOnly" order "seq" - model "closed"gt
- ltAttributeType name "shipID" dttype
"id" - required "yes"/gt
- ltattribute type "shipID"/gt
- ltelement type "duration"/gt
- lt/ElementTypegt
- ltElementType name "duration" content
"textOnly" - model "closed" dttype "date"/gt
52using data types a conforming xml document
- lt?xml version "1.0"?gt
- lt!-- Fig. 7.14 id.xml --gt
- lt!--Demonstrating ID and IDREF --gt
- ltbookstore xmlns "x-schemaid-schema.xml"gt
- ltshipping shipID "s1"gt
- ltdurationgt2000-08-01lt/durationgt
- lt/shippinggt
- ltshipping shipID "s2"gt
- ltdurationgt2000-08-20lt/durationgt
- lt/shippinggt
- ltbook shippedBy "s1"gt
- Java How to Program 3rd edition.
- lt/bookgt
- ltbook shippedBy "s2"gt
- C How to Program 3rd edition.
- lt/bookgt
- ltbook shippedBy "s2"gt
- C How to Program 3rd edition.
- lt/bookgt
53id.xml in validator
54Schema for an inventory database
- lt?xml version "1.0"?gt
- lt!-- Fig. 7.16 inventory-schema.xml --gt
- lt!-- Data type example --gt
- ltSchema xmlns "urnschemas-microsoft-comxml-dat
a" - xmlnsdt "urnschemas-microsoft-comdata
types"gt - ltElementType name "inventory" content
"eltOnly" - model "closed"gt
- ltelement type "book" minOccurs "0"
maxOccurs ""/gt - lt/ElementTypegt
- ltElementType name "book" content "eltOnly"
order "seq" - model "closed"gt
- ltAttributeType name "isbn" dttype
"string" - required "yes"/gt
- ltattribute type "isbn"/gt
55inventory database continued
- ltelement type "name"/gt
- ltelement type "price"/gt
- ltgroup order "one"gt
- ltelement type "quantity"/gt
- ltelement type "available"/gt
- lt/groupgt
- lt/ElementTypegt
- ltElementType name "name" content
"textOnly" model "closed" - dttype "string"/gt
- ltElementType name "price" content
"textOnly" model "closed" - dttype "float"/gt
- ltElementType name "quantity" content
"textOnly" - dttype "int" model "closed"/gt
- ltElementType name "available" content
"textOnly"
56a conforming document inventory.xml
- lt?xml version "1.0"?gt
- lt!-- Fig. 7.17 inventory.xml --gt
- lt!-- Data type example --gt
- ltinventory xmlns "x-schemainventory-schema.xml"
gt - ltbook isbn "0-13-012507-5" inStock "yes"gt
- ltnamegtJava How to Program 3/elt/namegt
- ltpricegt68.00lt/pricegt
- ltquantitygt200lt/quantitygt
- lt/bookgt
- ltbook isbn "0-13-028418-1" inStock "no"gt
- ltnamegtPerl How to Programlt/namegt
- ltpricegt68.00lt/pricegt
- ltavailablegt2000-12-15lt/availablegt
- lt/bookgt
- lt/inventorygt
57inventory in validator with one book node opened
58Heres what inventory looks like opened in IE
59My own database schema
- lt?xml version "1.0"?gt
- lt!-- classlist-schema.xml --gt
- lt!-- Data type example --gt
- ltSchema xmlns "urnschemas-microsoft-comxml-dat
a" - xmlnsdt "urnschemas-microsoft-comdata
types"gt - ltElementType name "classlist" content
"eltOnly" - model "closed"gt
- ltelement type "student" minOccurs "0"
maxOccurs ""/gt - lt/ElementTypegt
- ltElementType name "student" content
"eltOnly" order "seq" - model "closed"gt
- ltAttributeType name "ssn" dttype
"string" - required "yes"/gt
- ltattribute type "ssn"/gt
- ltAttributeType name "Matriculated"
dttype "enumeration" - dtvalues "yes no" default "no"/gt
- ltattribute type "Matriculated"/gt
-
60my own database schema continued
- ltelement type "name"/gt
- ltelement type "year"/gt
- ltgroup order "seq"gt
- ltelement type "address"/gt
- ltelement type "credits"/gt
- ltelement type "birthdate"/gt
- lt/groupgt
- lt/ElementTypegt
- ltElementType name "name" content
"textOnly" model "closed" - dttype "string"/gt
- ltElementType name "year" content
"textOnly" model "closed" - dttype "string"/gt
- ltElementType name "address" content
"textOnly" - dttype "string" model "closed"/gt
- ltElementType name "credits" content
"textOnly" - dttype"int" model"closed"/gt
- ltElementType name "birthdate" content
"textOnly" - dttype "date" model "closed"/gt
- lt/Schemagt
61Check if your schema is well-formed in validator
62an xml document satisfying this schema
- lt?xml version "1.0"?gt
- lt!-- myclass.xml --gt
- lt!-- Data type example --gt
- ltclasslist xmlns "x-schemaclasslist-schema.xml"
gt - ltstudent ssn "000-11-2222" Matriculated
"yes"gt - ltnamegtBob Smithlt/namegt
- ltyeargtsophomorelt/yeargt
- ltaddressgt123 Park Stlt/addressgt
- ltcreditsgt15lt/creditsgt
- ltbirthdategt1988-04-15lt/birthdategt
- lt/studentgt
- lt/classlistgt
63myclass has 4 students and is well-formed
64Schema following w3c standards xsd file
- lt?xml version "1.0"?gt
- lt!-- Figure 7.20 xml-schema.xsd --gt
- lt!-- Example W3C XML Schema --gt
- ltxsdschema xmlnsxsd "http//www.w3.org/2000/10
/XMLSchema"gt - ltxsdelement name "message" type
"xsdstring"/gt - ltxsdelement name "greeting" type
"greetingType"/gt - ltxsdcomplexType name "greetingType" content
"mixed"gt - ltxsdelement ref "message"/gt
- lt/xsdcomplexTypegt
- ltxsdelement name "myMessage" type
"myMessageType"/gt - ltxsdcomplexType name "myMessageType"gt
- ltxsdelement ref "greeting" minOccurs
"0" - maxOccurs "1"/gt
- ltxsdelement ref "message" minOccurs
"1" - maxOccurs "unbounded"/gt
- lt/xsdcomplexTypegt
- lt/xsdschemagt
65A conforming xml document
- lt?xml version "1.0"?gt
- lt!-- Fig. 7.19 intro3.xml --gt
- lt!-- Introduction to W3C XML Schema --gt
- ltmyMessage
- xmlnsxsd "http//www.w3.org/2000/10/XMLSche
ma-instance" - xsdnoNamespaceSchemaLocation
"xml-schema.xsd"gt - ltgreetinggtWelcome to W3C XML
Schema!lt/greetinggt - ltmessagegtThis is a message.lt/messagegt
- ltmessagegtThis is another message.lt/messagegt
- lt/myMessagegt
66It gets errors in MS Validator
67W3C schema example (previous slide) parsed by
Xerces(not sure about weird chars in output)
- C\xerces-1_2_0gtjava dom.DOMWriter intro3.xml
- intro3.xml
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltmyMessage xmlnsxsd"http//www.w3.org/2000/10/XM
LSchema-ineûÅ?nce" xsdnoNamespaceSchemaLocation - "xml-schema.xsd"gt
- ltgreetinggtWelcome to W3C XML
Schema!lt/greetinggt - ltmessagegtThis is a message.lt/messagegt
- ltmessagegtThis is another message.lt/messagegt
- lt/myMessagegt
68intro3.xml parsed again by Xerces using DOMCount2
- C\XERCES1gtDOMCount2.bat
- C\XERCES1gtset PATHPATHc\progra1\java\jdk15
1.0_0\binC\Progra1\Java\jdk15.0_0\bin - C\XERCES1gtset CLASSPATHCLASSPATHc\xerces-1_
2_0\xerces.jarc\xerces-1_2_0 - \xercesSamples.jarc\xerces-1_2_0\xerces.jarc\x
erces-1_2_0\xercesSamples.jar - C\xerces-1_2_0gtjava dom.DOMCount -p
dom.wrappers.DOMParser intro3.xml - intro3.xml 90 ms (4 elems, 2 attrs, 0 spaces, 83
chars) - C\XERCES1gt