Download presentation
Presentation is loading. Please wait.
Published byLouise Wilson Modified over 9 years ago
1
1 Dr Alexiei Dingli XML Technologies X-Schema
2
2 XML-based alternative to DTD Describes the structure of an XML document Also referred to as XML Schema Definition (XSD) What is X-Schema? (1)
3
3 defines elements that can appear in a document defines attributes that can appear in a document defines which elements are child elements defines the order of child elements defines the number of child elements defines whether an element is empty or can include text defines data types for elements and attributes defines default and fixed values for elements and attributes What is X-Schema? (2)
4
4 XML Schemas are extensible to future additions XML Schemas are richer and more powerful than DTDs XML Schemas are written in XML XML Schemas support data types XML Schemas support namespaces X-Schema vrs DTD
5
5 describe allowable document content validate the correctness of data work with data from a database define restrictions on data define data formats convert data between different data types X-Schema makes it easy to
6
6 We know the language Can be edited with XML editors Can be parsed with XML parsers Can be manipulated with XML DOM Can be transformed with XSLT Why is it better to use an XML based schema?
7
7 Ensure secure data communication –3/11/2004 is the 3 rd of November or the 11 th of March? Can reuse schemas Use one or many in the same document Create own data types Benefits of X-Schemas
8
8 Tove Jani Reminder Don't forget me this weekend! How to use X-Schema
9
9 The actual schema
10
10 Root element of any schema May contain attributes –xmlns:xs="http://www.w3.org/2001/XMLSchema" Indicate the XSchema namespace –targetNamespace="http://www.um.edu.mt" Indicate that the elements defined (to, from, etc) come from the above namespace –xmlns="http://www.um.edu.mt" Sets the default namespace –elementFormDefault="qualified“ Qualified = all elements can be validated Unqualified = only root element can be validated with the namespace element
11
11 A simple element contains only text But it can have different types or restrictions (facets) Elements
12
12 xs:string xs:decimal xs:integer xs:boolean xs:date xs:time Element Built-In Types
13
13 Default and Fixed types
14
14 Simple elements cannot have attributes Only complex elements have attributes An attribute is declared as a simple type Attributes
15
15 * Optional by default (unless specified) Default, Fixed and Optional attributes
16
16 Restrictions (Facets) - Range
17
17 Restrictions (Facets) – Set 1
18
18 Restrictions (Facets) – Set 2
19
19 Restrictions (Facets) - Pattern
20
20 Regular expressions example [A-Z]any letter uppercase [A-Z][A-Z]two letters uppercase [a-zA-Z]any letter any case [xyz]x or y or z [0-9]any number one digit ([A-Z])+ one or more ([A-Z])*zero or more male|femaleeither or [a-zA-Z]{8}exactly 8 characters Restrictions (Facets) - Patterns
21
21 Restricting white space (1)
22
22 Value can be –Preserve Do not remove white space –Replace Replace line feeds, tabs, spaces, and carriage returns with spaces –Collapse Same as replace but collapse multiple spaces into one Restricting white space (2)
23
23 Restrictions (Facets) - Length
24
24 ConstraintDescription enumerationDefines a list of acceptable values fractionDigitsSpecifies the maximum number of decimal places allowed. Must be equal to or greater than zero lengthSpecifies the exact number of characters or list items allowed. Must be equal to or greater than zero maxExclusiveSpecifies the upper bounds for numeric values (the value must be less than this value) maxInclusiveSpecifies the upper bounds for numeric values (the value must be less than or equal to this value) maxLengthSpecifies the maximum number of characters or list items allowed. Must be equal to or greater than zero minExclusiveSpecifies the lower bounds for numeric values (the value must be greater than this value) minInclusiveSpecifies the lower bounds for numeric values (the value must be greater than or equal to this value) minLengthSpecifies the minimum number of characters or list items allowed. Must be equal to or greater than zero patternDefines the exact sequence of characters that are acceptable totalDigitsSpecifies the exact number of digits allowed. Must be greater than zero whiteSpaceSpecifies how white space (line feeds, tabs, spaces, and carriage returns) is handled Summarising Restrictions
25
25 1.empty elements 2.elements that contain only other elements 3.elements that contain only text 4.elements that contain both other elements and text Complex Elements
26
26 Ex Complex Empty Elements
27
27 Contains only other elements Complex Elements Only
28
28 John Smith Complex Elements Only Ex
29
29 Eg 35 Complex TextOnly Element
30
30 Complex Mixed Content
31
31 Order indicators: –All All must occur but in any order –Choice Either or can occur –Sequence Must appear in a specified sequence Occurrence indicators: –maxOccurs –minOccurs Group indicators: Group elements or attributes together and allow for reuse –Group name –attributeGroup name 7 Indicators
32
32 All, Choice, Sequence indicator
33
33 <xs:element name="child_name" type="xs:string" maxOccurs="10" minOccurs="0"/> Occurrence indicator
34
34 <xs:element name="child_name" type="xs:string" maxOccurs="10" minOccurs="0"/> *allows for any element or attribute but it has to be defined just the same in another XSchema and
35
35 Allows for … John Substitutions
36
36 NameDescription ENTITIES ENTITY IDA string that represents the ID attribute in XML (only used with schema attributes) IDREFA string that represents the IDREF attribute in XML (only used with schema attributes) IDREFS languageA string that contains a valid language id NameA string that contains a valid XML name NCName NMTOKENA string that represents the NMTOKEN attribute in XML (only used with schema attributes) NMTOKENS normalizedStringA string that does not contain line feeds, carriage returns, or tabs stringA string tokenA string that does not contain line feeds, carriage returns, tabs, leading or trailing spaces, or multiple spaces String Datatype
37
37 NameDescription dateDefines a date value dateTimeDefines a date and time value durationDefines a time interval gDayDefines a part of a date - the day (DD) gMonthDefines a part of a date - the month (MM) gMonthDayDefines a part of a date - the month and day (MM-DD) gYearDefines a part of a date - the year (YYYY) gYearMonthDefines a part of a date - the year and month (YYYY-MM) timeDefines a time value Date Datatype
38
38 NameDescription byteA signed 8-bit integer decimalA decimal value intA signed 32-bit integer integerAn integer value longA signed 64-bit integer negativeIntegerAn integer containing only negative values (.., -2, -1.) nonNegativeIntegerAn integer containing only non-negative values (0, 1, 2,..) nonPositiveIntegerAn integer containing only non-positive values (.., -2, -1, 0) positiveIntegerAn integer containing only positive values (1, 2,..) shortA signed 16-bit integer unsignedLongAn unsigned 64-bit integer unsignedIntAn unsigned 32-bit integer unsignedShortAn unsigned 16-bit integer unsignedByteAn unsigned 8-bit integer Numeric Datatype
39
39 Example
40
40 Define an XML Vocabulary for a Toaster Markup Language (TML) using XSchema It must support features such as: –Print message on toast –Display on LCD –Time stamp Exercise
41
41 Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.