XML Schema Describing the structure of XML documents. A very brief introduction 1XML Schema
What is XML Schema? XML schema is used to describe the structure of XML documents – Name of elements + attributes – Sub-elements – Sequence of elements, etc. XML Schema is itself an XML application XSD = XML Schema Definition – Filename.xsd holds an XML Schema XML Schema is a W3C recommendation, XML Schema
Validation An XML documents can be validated against its XML schema – Check that all element, etc. Of the XML document conforms with the XML schema XML Schema3
XML schema, example XML Schema4
XML schema support in Visual Studio Ultimate You can generate an XML schema from an XML document – Menu: XML → Create Schema The schema is saved in your home directory. If you want it in your Visual Studio you must 1.Right click the project node 2.Chose” Add Existing Item…” You can validate XML documents as you write them 1.With your XML document, go to the ”Properties” window 2.Select ”Schemas” and press the small ”…” button 3.In Visual Studio it’s not enough to make a link from the XML document to the XML schema file (next slide) XML Schema5
Reference to an XML schema from an XML document <students xmlns=" xmlns:xsi=" xsi:schemaLocation=" students.xsd"> Anders Roskilde Bill London XML Schema6
XSD simple elements Simple element has no child elements – – Some common types xs:string, xs:decimal, xs:integer xs:boolean xs:date, xs:time User defines types – Restrictions on data types, example: interval XML Schema7
XSD complex elements Four kinds of complex elements – empty elements may have attributes – elements that contain only other elements – elements that contain only text – elements that contain both other elements and text Attribute – Child element of – XML Schema8