XML Schema PB138 What is XML Schema ● XML document How to validate ● Use example people.xsd to validate people. xml xmllint --schema mySchema.xsd neco.xml Basic XML Schema assigns types Basic builtin types ● Type “xs:string” ● Type “xs:anyType” Basic XML Schema assigns types Create an xsd that validates, that people.xml has root element “name” How to write schema 1. Define data types 2. Assign data types to nodes Defining Data Types ● Nodes in XML have data types ● Attrs or Elements may be of Simple Type Data type of element with elements ● all ● choice How to define “any element” Complex Types ● ● may contain sequence of elements (all, choice....) ○ minOccurs ○ maxOccurs ● After the sequence, all, choice you can declare attrs: Simple Types ● We may specify precisely by inheritance ○ name is special type of string ○ date is special type of string ○ positive integer is special type of string Simple Types Enumeration ● Create an enumeration for phone codes: “+421; +420” Enrich People XML and write XSD ● Add attribute BirthDate with regex format “MM-DD-YYYY” ● Write XSD schema for people.xml Elements just with Attributes ● Complex type, simple content Must be inside ! ... xs:unique Must be inside ! ... xs:key xs:keyref ... What else is XML schema? ● Namespaces ● Defining uniqueness (we need XPath) ● Element/Attribute groups ● Unions ● References ● Includes/Imports ● Annotations