1 / 8

XML Schema

XML Schema. Describing the structure of XML documents. A very brief introduction. 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

ave
Télécharger la présentation

XML Schema

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML Schema Describing the structure of XML documents. A very brief introduction XML Schema

  2. 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, 2001 XML Schema

  3. 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 Schema

  4. XML schema, example <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="students"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="student"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="address" type="xs:string" /> </xs:sequence> <xs:attribute name="id" type="xs:unsignedShort" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> XML Schema

  5. 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 • Right click the project node • Chose” Add Existing Item…” • You can validate XML documents as you write them • With your XML document, go to the ”Properties” window • Select ”Schemas” and press the small ”…” button • In Visual Studio it’s not enough to make a link from the XML document to the XML schema file (next slide) XML Schema

  6. Reference to an XML schemafrom an XML document <?xml version="1.0" encoding="utf-8" ?> <students xmlns="http://www.rhs.dk/andersb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.rhs.dk/andersb students.xsd"> <student id="14593"> <name>Anders</name> <address>Roskilde</address> </student> <student id="1111"> <name>Bill</name> <address>London</address> </student> </students> XML Schema

  7. XSD simple elements • Simple element has no child elements • <xs:element name="xxx" type="yyy"/> • Some common types • xs:string, • xs:decimal, xs:integer • xs:boolean • xs:date, xs:time • User defines types • Restrictions on data types, example: interval • <xs:element name="age"> <xs:simpleType>    <xs:restriction base="xs:integer">      <xs:minInclusive value="0"/>      <xs:maxInclusive value="120"/>    </xs:restriction></xs:simpleType></xs:element> XML Schema

  8. XSD complex elements • Four kinds of complex elements • empty elements • may have attributes • elements that contain only other elements • <xs:sequence> • elements that contain only text • <xs:simpleContent> • elements that contain both other elements and text • <xs:complexType mixed="true"> • Attribute • Child element of <xs:complexType …> • <xs:attribute name="xxx" type="yyy"/> XML Schema

More Related