Download presentation
Presentation is loading. Please wait.
Published byRoberta Simmons Modified over 9 years ago
1
XML Schemas J. Pontes November 15, 2004
2
Schemas Defines what a set of one or more document can look like. What elements it contains, order, content, and attributes. These documents are written in XML Schema language
3
DTD Disadvantages compared to XML Cannot be parsed by an XML parser All declarations in DTD are global (impossible to define two elements with same name.) DTD cannot control what kind of information a given element or attribute can contain.
4
What XML Schema Buys You One can define both global elements (used same way all along document) and local elements (particular meaning in a particular context). XML Schemas contain a system of data types. Gives more control over XML document
5
Schema: types of content Simple Type – text only Complex Types – contain other elements or attributes.
6
Simple Type Date Integer String Customer built types –In DTD we used #OCDATA to capture a name, a date or practically anything.
7
Complex Type Describe the structure of a document, rather than content. Complex Types –Elements that contain elements –Elements that contain element and text –Elements that contain only text –Elements that are empty Each may contain attributes
8
Examples of Built-in Simple Types
9
Custom Simple Type This type limits the content of elements (zipcodeType) to a string with 5 digits, an optional hyphen and 4 extra digits.
10
Complex Type Definition <xsd:element name=“animal” type=“animalType” minOccurs=“1” maxOccurs=“unbounded”/> Defines endType. It contains another element animal defined with another complex type animalType to define a particular element
11
Local end Global declarations Global –Declared at top level of a schema, just immediately below xsd:schema element. They are available to be used throughout the the rest of the schema. –Global element declaration do not determine where an element can appear in the XML document – they only determine what the element will look like. –A global element declaration must be explicitly referenced in order to have it appear in a corresponding XML document. Simple –Locally declared elements. Limited to the complex type definition in which they are declared and may not not be used elsewhere in the schema. –Such locally declared elements are automatically referenced.
12
Example of Local and Global Elements http://www.w3.org/2000/10/XMLSchema <xsd:element ref=“name” minOccurs=“2”/> … automatically referenced. manually referenced. Same name different definitions.
13
Cont’d <xsd:element ref=“name” minOccurs=“1” maxOccurs=“unbounded”/> … … Same name different definitions.
14
Beginning a Simple Schema //Declaring XML <xsd:schema xmlns:xsd=“ http://www.w3.org/2000/10/XMLSchema ”http://www.w3.org/2000/10/XMLSchema Any element or type that is prefixed with xsd: will be recognized as coming from namespace* Schema rules go in this space. Save you schema as a text only with the.xsd extension.
15
Indicating a Location <endanged_species xmlns:xsd=“ http://www.w3.org/2000/10/XMLSchema-instance ”http://www.w3.org/2000/10/XMLSchema xsi:noNamespaceSchemaLocation= “ http://www.cookwook.com/ns/end_species/end_species.xsd ”> *http://www.cookwook.com/ns/end_species/end_species.xsd * file.xsd previously created.
16
Making Schemas Annotations <xsd:schema xmlns:xsd=“ http://www.w3.org/2000/10/XMLSchema ”http://www.w3.org/2000/10/XMLSchema This schema will be used to validate the set of XML documents for the Endangered Species Project.
17
Defining Simple Types When declaring an element, you choose its name and what kind of content it should contain. –xsd:string – string of characters –xsd:decimal – decimal number –xsd:boolean – true of false –xsd:date – CCYY-MM-DD –xsd:time - –xsd:uriReference - element will contain an URL –xsd:language – two letter language listed in ISO639 –Custom – name of a custom simple type. –Code.xsd –Code.xml 500 pounds 28 When a value is an integer or a string?
18
More XML Data Types Click Here for More Data Types Click Here for More Data Types
19
Date and Time Data Types Code.xsd <xsd:element name=“gestation” type=“xsd:timeDuration”/> (represent a certain amount of time) Code.xml P3M15D (PnYnMnDTnHnMnS) Period n - non negative T begins optional time section
20
Code.xsd xsd:element name=“bedtime” type=“xsd.time:/> Code.xml 20:15:05-05:00>/bedtime> Date and Type Data Types
21
Additional xsd:time xsd:time (hh:mm:ss.sss) xsd:timeInstant (CCYY-MM-DDTh:mm:ss.sss) xsd:date CCYY-MM-DD xsd:month (CCYY-MM xsd:year (CCYY) xsd:century (CC) xsd:recurringDate xsd:recurringDay
22
Number Type xsd:decimal xsd:integer xsd:positiveinteger xsd:negativeinteger xsd:float xsd:double
23
XML Validator STG XML Validation
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.