160 likes | 259 Vues
XML Schema. http://www.w3.org/TR/xmlschema-1 http://www.w3.org/TR/xmlschema-2 ( W3C Working Draft 17 December 1999 ) http://msdn.microsoft.com/xml/xmlguide/ schema-overview.asp. Outline. Introduction to XML Schema Defining Elements and Attributes Content Model Data Types Extensibility.
E N D
XML Schema http://www.w3.org/TR/xmlschema-1 http://www.w3.org/TR/xmlschema-2 (W3C Working Draft 17 December 1999) http://msdn.microsoft.com/xml/xmlguide/ schema-overview.asp EECS 684: Current Topics in Databases
Outline • Introduction to XML Schema • Defining Elements and Attributes • Content Model • Data Types • Extensibility EECS 684: Current Topics in Databases
Introduction • An XML Schema specifies the structure of an XML document and constrains on its content • Unlike DTD, XML Schema uses XML syntax • An XML Schema is useful for • data validation • data interchange EECS 684: Current Topics in Databases
An XML Document <invoice> <billingAddress year=“2000”> <name>Alice Smith</name> <street>12 Maple Street</street> <city>Ann Arbor</city> <state>MI</state> </billingAddress> <comment>A good customer</comment> </invoice> EECS 684: Current Topics in Databases
Defining & Using Types <type name = “address”> <element name = “name” type = “string” /> <element name = “street” type = “string” /> <element name = “city” type = “string” /> <element name = “state” type = “string” /> <attribute name = “year” type = “integer”/> </type> <element name = “billingAddress” type = “address” /> <element name = “comment” type = “string” /> EECS 684: Current Topics in Databases
Content Model • Content • minOccurs and maxOccurs • Order • Group EECS 684: Current Topics in Databases
Content • An element can contain text, other elements, a mixture of text and elements, or nothing at all • Use the content attribute • Possible values are “textOnly”, “elementOnly”, “mixed”, and “empty” • An example <type name = “street” content=“textOnly” /> EECS 684: Current Topics in Databases
minOccurs and maxOccurs • Specify how many times an element can appear within another element • Use the minOccurs attribute <element name = “comment” minOccurs = “0” /> • Use the maxOccurs attribute <element name =“item” maxOccurs = “*” /> EECS 684: Current Topics in Databases
Order • Specify whether sub-elements are required to appear in a certain order, and if only one sub-element can appear • Use the order attribute • Possible values are “seq”, “choice”, and “all” <type name = “address” order=“seq” /> EECS 684: Current Topics in Databases
Group • Specify constraints on a specific set of sub-elements <type name = “item”> <group order = “choice”> <element type = “product”> <element type = “backOrderedProduct” /> </group> <element type = “quantity” /> <element type = “price” /> </type> • Accept order, minOccurs, and maxOccurs attributes EECS 684: Current Topics in Databases
Data Types • Unlike DTD, XML Schema allows you to specify a data type for an element or an attribute • Data types indicate the format of data • Data types categorization • atomic vs. aggregate data types • primitive vs. generated data types • built-in vs. user-generated data types EECS 684: Current Topics in Databases
Defining Data Types • Defining “i4” (signed 4-byte integer) from the built-in data type integer <datatype name=“i4” source=“integer”> <minInclusive value = ‘-2147483648’> <maxInclusive value = ‘2147483648’> </datatype> • minInclusive and maxInclusive facets specify the bounds of the values EECS 684: Current Topics in Databases
Defining Data Types (Cont.) • Defining “amount” <datatype name = “amount” source =“decimal”> <precision value = ‘8’ /> <scale value = ‘2’ /> </datatype> • Use precision and scale facets to constrain the range of the base type. EECS 684: Current Topics in Databases
Defining Data Types (Cont.) • Defining a data type which limit the values of dates to the three US holidays <datatype name = “holidays” source=“date”> <enumeration value=‘--01-01’ /> <enumeration value=‘--07-04’ /> <enumeration value=‘--12-25’ /> </datatype> • enumeration facet constrains the value space of the data type to the specified list. EECS 684: Current Topics in Databases
Referencing Other Schemas • The namespace declaration • begins with “xmlns:” • followed by a “prefix” • then the URI of the other schema • Example <type name = “shipTo” xmlns:abcde=“http://ecommerce.com/a.xml”> <element type = “abcde:address” /> </type> EECS 684: Current Topics in Databases
Conclusion • XML Schema allows you to • define types for elements and attributes • build a content model • define your own data types • refer to other schemas EECS 684: Current Topics in Databases