XML SCHEMA Peter Binkley LIS 598 SPECIAL TOPICS
XML SCHEMA Peter Binkley LIS 598: SPECIAL TOPICS: Information Modeling in XML Aug. 2009
VALIDATION Purposes: Express the permissible structure for a type of document, so that: structural or content errors can be detected by an automated process Authoring and documentation tools can provide help to users Express a way of reading the document that enhances the content in a standard way (e. g. provides default values) – Dangerous!
SCHEMA VS DOCUMENT TYPE DEFINITION (DTD) DTD came from SGML world Non-XML format Difficult to understand Schema: pure XML May eventually replace DTD altogether Easier to work with
SAMPLE SCHEMA <? xml version="1. 0"? > <xs: schema xmlns: xs="http: //www. w 3. org/2001/XMLSchema"> <xs: element name="book"> <xs: complex. Type> <xs: sequence> <xs: element name="author" type="xs: string"/> <xs: element name="title" type="xs: string"/> </xs: sequence> </xs: complex. Type> </xs: element> </xs: schema> <book> <author>Jane Austen</author> <title>Sense and Sensibility</title> </book>
DTD (FOR COMPARISON) <!ELEMENT book (author, title)> <!ELEMENT author (#PCDATA)> <!ELEMENT title (#PCDATA)> <book> <author>Jane Austen</author> <title>Sense and Sensibility</title> </book>
GROUPING xs: all xs: sequence xs: choice Occurences: <xs: element name="author" type="xs: string" min. Occurs="0" max. Occurs="3"/>
TYPES xs: string xs: decimal xs: integer xs: boolean xs: date xs: time Use: <xs: element name="birth" type="xs: date"/> <xs: attribute name="lang" type="xs: string"/>
RESTRICTIONS ON VALUES <xs: attribute name="lang"> <xs: simple. Type> <xs: restriction base="xs: string"> <xs: enumeration value="eng"/> <xs: enumeration value="fr"/> </xs: restriction> </xs: simple. Type> </xs: attribute> Other kinds of restrictions: length, min. Length, max. Length, pattern, etc.
DEFINITION BY REFERENCE <xs: complex. Type name="personinfo”> <xs: sequence> <xs: element name="firstname" type="xs: string"/> <xs: element name="lastname" type="xs: string"/> </xs: sequence> </xs: complex. Type> <xs: element name="author" type="personinfo"/> <xs: element name="subject. Person" type="personinfo"/>
UNSTRUCTURED (MIXED) CONTENT <xs: element name="p"> <xs: complex. Type mixed="true"> <xs: all> <xs: element name="em" type="xs: string” min. Occurs=“ 0”/> <xs: element name="strong" type="xs: string” min. Occurs=“ 0”/> </xs: all> </xs: complex. Type> </xs: element> <p>This is <em>so</em> <strong>interesting<strong>. </p>
- Slides: 10