Introduction to XML Schema John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel: (x2073)
Contents Introduction Document Type Definitions - reminder W3C Schema –Schema Structures –Built-In Types Summary Find Out More
Introduction Schema –a diagram, plan or framework –XML – a document that describes an XML document.
Introduction Purpose –Data validation –Contract –System documentation –Processing information
Introduction Schema Data Validation –Element and attribute structure –Element ordering –Value constraints Built-in data types Size and pattern constraints Enumerations –Uniqueness constraints
Introduction Schema Languages –Document Type Definitions (DTD’s) –W3C XML Schema –OASIS RELAX NG –Schematron
Document Type Definitions DTD Benefits –Easy to understand and implement –Lightweight alternative to schemas
Document Type Definitions DTD Limitations –Use non-XML syntax –Only limited support for data typing and namespaces –Difficult to extend
W3C Schema W3C Recommendation –XML Schema Part 0: Primer Introduction (guidance) –XML Schema Part I: Structures defines schema components –XML Schema Part 2: Datatypes defines built-in datatypes and their restrictions
W3C Schema Structures Most commonly used structures: –element s and attribute s –simpleType s –complexType s –model group s –minOccurs and maxOccurs –annotation and documentation –schema and namespaces
W3C Schema Structures element and attribute –Basic building blocks of documents
W3C Schema Structures element and attribute –valid instances of Record element Arnett John M Smith FEMALE
W3C Schema Structures element and attribute –invalid Record element instance Mr Arnett John M 06-Jan-63
W3C Schema Structures simpletype Definitions –Define element content –Character data only - no nested (child) elements permitted –No attribute s permitted –Always derived from a built-in types (using restriction)
W3C Schema Structures simpletype definition examples
W3C Schema Structures complexType Definitions –Define element content –Child elements and character data permitted –attribute s permitted
W3C Schema Structures complexType definition examples
W3C Schema Structures –sequence elements must occur in the order specified –choice one of several child elements must be selected –all 0 or 1 occurences in any order Model group s
W3C Schema Structures Model group examples
W3C Schema Structures Model group s –Valid instances of Record element Arnett John M Smith Jane F 28
W3C Schema Structures minOccurs and maxOccurs –control the occurence of element instances minOccurs=“0” –occurrence is optional maxOccurs=“unbounded” –multiple occurences allowed –may be applied to any child element, sequence or choice
W3C Schema Structures minOccurs and maxOccurs examples
W3C Schema Structures minOccurs and maxOccurs –Valid instances of Record element Arnett John Gordon M Smith Jane 28
W3C Schema Structures Namespaces –W3C namespace http// element, complexType, sequence, etc –targetNamespace Optional User defined One per schema document
W3C Schema Structures schema with namespaces
W3C Schema Structures annotation and documentation The sex of an individual for administrative purposes.
W3C Schema Structures annotation and documentation This is used when the sex cannot be determined for physical reasons, e.g. a new born baby
Built-in Simple Types 44 built-in simple types - most are atomic Used directly in schemas or used to create user-defined simple types
Built-in Simple Types String-based types –string –normalizedString –token
Built-in Simple Types Numeric Types –float and double –decimal –integer
Built-in Simple Types Date and Time Types –date –time –dateTime –gYear, gMonth, gDay –duration
Built-in Simple Types Others –boolean –base64Binary and hexBinary –anyURI
Built-in Simple Types Facets –length –minLength –maxLength –minExclusive –minInclusive –maxExclusive –minExclusive –totalDigits –fractionDigits –whiteSpace –pattern –enumeration
Built-in Simple Types Length facets This is a valid value This is an invalid value because it contains more than 35 characters
Built-in Simple Types enumeration facet NK Male
Built-in Simple Types pattern facet
Advanced Features Multi-document schemas Complex type derivation Reusable groups Element substitution Schema redefinition Identity constraints Schema design
Summary Used to validate structure and values XML instance documents Uses XML syntax W3C Recommendation specifies data structures and built-in types Supports namespaces Has many advanced features, incl. several extensibilty mechanisms
Find Out More XML Schema Part 0: Primer – XML Schema Part 0: Structures – XML Schema Part 0: Datatypes –