2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 – Schemas Outline 7.1Introduction 7.2Schemas vs. DTDs 7.3Microsoft XML Schema: Describing Elements 7.4Microsoft XML Schema: Describing Attributes 7.5Microsoft XML Schema: Data types 7.6W3C XML Schema 7.7Case Study: Writing a Microsoft XML Schema for the Day Planner Application 7.8Internet and World Wide Web Resources
2001 Prentice Hall, Inc. All rights reserved. Outline 2 Fig. 7.1Microsoft XML Schema document <ElementType name = "message" content = "textOnly" 9 model = "closed"> 10 Text messages <ElementType name = "greeting" model = "closed" 14 content = "mixed" order = "many"> <ElementType name = "myMessage" model = "closed" 19 content = "eltOnly" order = "seq"> <element type = "greeting" minOccurs = "0" 22 maxOccurs = "1"/> 23 <element type = "message" minOccurs = "1" 24 maxOccurs = "*"/>
2001 Prentice Hall, Inc. All rights reserved. Outline 3 Fig. 7.2XML document that conforms to intro- schema.xml Welcome to XML Schema! 9 This is the first message This is the second message. 13
2001 Prentice Hall, Inc. All rights reserved. 4
Outline 5 Fig. 7.3Well-formed, but invalid XML document Welcome to XML Schema! 9 10 This is a message that contains another message. 11 This is the inner message
2001 Prentice Hall, Inc. All rights reserved. 6
7 Fig. 7.4ElementType element attributes.
2001 Prentice Hall, Inc. All rights reserved. 8 Fig. 7.4ElementType element attributes. (Part 2)
2001 Prentice Hall, Inc. All rights reserved. 9 Fig. 7.5Element ElementType’s child elements.
2001 Prentice Hall, Inc. All rights reserved. 10 Fig. 7.6Element element attributes.
2001 Prentice Hall, Inc. All rights reserved. 11 Fig. 7.7Element group’s attributes.
2001 Prentice Hall, Inc. All rights reserved. 12 Fig. 7.8Element AttributeType’s attributes.
2001 Prentice Hall, Inc. All rights reserved. 13 Fig. 7.9Element attribute’s attributes.
2001 Prentice Hall, Inc. All rights reserved. Outline 14 Fig Demonstrating AttributeType and attribute <ElementType name = "contact" content = "eltOnly" order = "seq" 9 model = "closed"> <ElementType name = "name" content = "textOnly" 24 model = "closed"/> <ElementType name = "address1" content = "textOnly" 27 model = "closed"/> 28
2001 Prentice Hall, Inc. All rights reserved. Outline 15 Fig Demonstrating AttributeType and attribute. (Part 2) 29 <ElementType name = "address2" content = "textOnly" 30 model = "closed"/> <ElementType name = "city" content = "textOnly" 33 model = "closed"/> <ElementType name = "state" content = "textOnly" 36 model = "closed"/>
2001 Prentice Hall, Inc. All rights reserved. Outline 16 Fig. 7.11Contact list that conforms to contact- schema.xml Jane Doe Main St. 9 Sometown 10 Somestate
2001 Prentice Hall, Inc. All rights reserved. 17
2001 Prentice Hall, Inc. All rights reserved. 18 Fig. 7.12Some Microsoft XML Schema data types.
2001 Prentice Hall, Inc. All rights reserved. Outline 19 Fig. 7.13Using Microsoft XML Schema data types <Schema xmlns = "urn:schemas-microsoft-com:xml-data" 7 xmlns:dt = "urn:schemas-microsoft-com:datatypes"> 8 9 <ElementType name = "bookstore" content = "eltOnly" 10 order = "many" model = "closed"> <ElementType name = "shipping" content = "eltOnly" order = "seq" 17 model = "closed"> 18
2001 Prentice Hall, Inc. All rights reserved. Outline 20 Fig. 7.13Using Microsoft XML Schema data types. (Part 2) 19 <AttributeType name = "shipID" dt:type = "id" 20 required = "yes"/> <ElementType name = "duration" content = "textOnly" 27 model = "closed" dt:type = "date"/> <ElementType name = "book" content = "textOnly" model = "closed" 30 dt:type = "string">
2001 Prentice Hall, Inc. All rights reserved. Outline 21 Fig. 7.14XML document conforming to id-schema.xml Java How to Program 3rd edition C How to Program 3rd edition C++ How to Program 3rd edition
2001 Prentice Hall, Inc. All rights reserved. 22
2001 Prentice Hall, Inc. All rights reserved. 23 Fig. 7.15Invalid XML document.
2001 Prentice Hall, Inc. All rights reserved. Outline 24 Fig. 7.16Schema for an inventory document <Schema xmlns = "urn:schemas-microsoft-com:xml-data" 7 xmlns:dt = "urn:schemas-microsoft-com:datatypes"> 8 9 <ElementType name = "inventory" content = "eltOnly" 10 model = "closed"> <ElementType name = "book" content = "eltOnly" order = "seq" 15 model = "closed"> <AttributeType name = "isbn" dt:type = "string" 18 required = "yes"/> <AttributeType name = "inStock" dt:type = "enumeration" 22 dt:values = "yes no" default = "no"/> 23 24
2001 Prentice Hall, Inc. All rights reserved. Outline 25 Fig. 7.16Schema for an inventory document. (Part 2) <ElementType name = "name" content = "textOnly" model = "closed" 35 dt:type = "string"/> <ElementType name = "price" content = "textOnly" model = "closed" 38 dt:type = "float"/> <ElementType name = "quantity" content = "textOnly" 41 dt:type = "int" model = "closed"/> <ElementType name = "available" content = "textOnly" 44 dt:type = "date" model = "closed"/> 45
2001 Prentice Hall, Inc. All rights reserved. Outline 26 Fig. 7.17XML document conforming to inventory- schema.xml Java How to Program 3/e Perl How to Program
2001 Prentice Hall, Inc. All rights reserved. Outline 27 Fig. 7.18W3C XML Schema document <xsd:element ref = "greeting" minOccurs = "0" 19 maxOccurs = "1"/> 20 <xsd:element ref = "message" minOccurs = "1" 21 maxOccurs = "unbounded"/> 22 23
2001 Prentice Hall, Inc. All rights reserved. Outline 28 Fig. 7.19Document that conforms to xml- schema.xsd <myMessage 7 xmlns:xsd = " 8 xsd:noNamespaceSchemaLocation = "xml-schema.xsd"> 9 10 Welcome to W3C XML Schema! 11 This is a message. 12 This is another message
2001 Prentice Hall, Inc. All rights reserved. 29
2001 Prentice Hall, Inc. All rights reserved. Outline 30 Fig. 7.20Microsoft XML Schema for dayplanner.xml <Schema xmlns = "urn:schemas-microsoft-com:xml-data" 7 xmlns:dt = "urn:schemas-microsoft-com:datatypes"> 8 9 <ElementType name = "planner" content = "eltOnly" 10 model = "closed">
2001 Prentice Hall, Inc. All rights reserved. Outline 31 Fig. 7.20Microsoft XML Schema for dayplanner.xml. (Part 2) <ElementType name = "note" content = "textOnly" model = "closed" 31 dt:type = "string">