Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML SCHEMA 1 CH 20. Objective 2 What’s wrong with DTDs? What is a schema? The W3C XML Schema Language Hello schemas Complex types Simple types Deriving.

Similar presentations


Presentation on theme: "XML SCHEMA 1 CH 20. Objective 2 What’s wrong with DTDs? What is a schema? The W3C XML Schema Language Hello schemas Complex types Simple types Deriving."— Presentation transcript:

1 XML SCHEMA 1 CH 20

2 Objective 2 What’s wrong with DTDs? What is a schema? The W3C XML Schema Language Hello schemas Complex types Simple types Deriving simple types

3 What’s wrong with DTDs? 3 XML is being used for object serialization, stock trading, remote procedure calls, vector graphics, and many more things 1. First issue - DTD lack data type, especially for element content a) - DTD can’t say that a PRICE element must contain a number b) There’s no way to say that a MONTH element must be an integer between 1 and 12 c) There’s no way to indicate that a TITLE must contain between 1 and 255 characters

4 What’s wrong with DTDs? Cont… 4 Data type is not needed for SGML was aimed For computer-to-computer exchange of information, data type is needed 2. The second problem is that DTDs have an unusual non-XML syntax Parsers and APIs that read an XML document can’t read a DTD

5 What’s wrong with DTDs? Cont… 5 This above example is not a legal XML. Reason You can’t begin an element name with an exclamation point TITLE is not an attribute. Neither is (#PCDATA) 3. The third problem is that DTDs are only marginally extensible and don’t scale very well

6 What’s wrong with DTDs? Cont… 6 It’s difficult to combine independent DTDs together in a sensible way XML applications can be defined before the entire DTD becomes completely unmanageable and incomprehensible 4. DTDs don’t allow you to do things that it really feels like you ought to be able to do

7 What’s wrong with DTDs? Cont… 7 DTDs cannot enforce the order or number of child elements in mixed content You can’t enforce constraints such as each PARAGRAPH element must begin with exactly one SUMMARY element that is followed by plain text

8 What’s wrong with DTDs? Cont… 8 Schemas are an attempt to solve all these problems by defining a new XML-based syntax for describing the permissible contents of XML documents that includes the following 1. Powerful data typing including range checking 2. Namespace-aware validation based on namespace URIs rather than on prefixes 3. Extensibility and scalability

9 What Is a Schema? 9  Schema simply mean form or shape Schema was a description of all the tables in a database(Oracle, MySQL, etc..) and the fields in the table Schema also described what type of data each field could contain. E.g. CHAR,INT, DATE and so on. An XML Schema describes the structure of an XML document Different kinds of schemas from different technologies, including vocabulary schemas, RDF schemas, organizational schemas, X.500 schemas, and of course, XML schemas

10 The W3C XML Schema Language 10 Was created by the W3C XML Schema Working Group based on many different submissions from a variety of companies and individuals There are no known patent, trademark, or other intellectual property restrictions that would prevent you from doing anything you might reasonably want to do with schemas

11 Hello Schemas cont… 11 Schema can be written and saved in any text editor that knows how to save Unicode files Schema documents are XML documents and have all the privileges and responsibilities of other XML documents

12 Hello Schemas 12 The greeting schema Hello XML! Hello XML! schema nametype schema nametype Save as.xsd

13 Hello Schemas 13 The root element of this and all other schemas is schema This must be in the http://www.w3.org/2001/XMLSchema namespace Namespace is bound to the prefix xsd or xs Elements are declared using xsd:element elements

14 Hello Schemas 14 The name attribute specifies which element is being declared This xsd:element element also has a type attribute whose value is the data type of the element

15 A first Look 15

16 Complex Types 16 The W3C XML Schema Language divides elements into complex and simple types A simple A simple type element is one such as GREETING that can only contain text and does not have any attributes It cannot contain any child elements Complex type elements can have attributes and can have child elements Most documents need a mix of both complex and simple elements

17 Complex Types cont… 17 yesiam.xml <SONG xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”song.xsd”> Yes I Am Melissa Etheridge Hugh Padgham Island Records 4:24 1993 Melissa Etheridge $1.25 <SONG xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”song.xsd”> Yes I Am Melissa Etheridge Hugh Padgham Island Records 4:24 1993 Melissa Etheridge $1.25

18 Complex Types cont… 18 Schema that describes the xml song.xsd <xsd:sequence> </xsd:sequence> <xsd:sequence> </xsd:sequence>

19 Complex Types cont… 19 xsd:complexType The xsd:complexType element defines a new type

20 Complex Types cont… 20 minOccurs and maxOccurs Specify the minimum and maximum number of instances of the element that may appear at that point in the document integer greater than or equal to zero The value of each attribute is an integer greater than or equal to zero The maxOccurs attribute can also have the value unbounded unbounded unbounded to indicate that an unlimited number of the particular element may appear See List 20-7 See List 20-7

21 Complex Types cont… 21 This schema says that every SongType element must have, in order: 1. Exactly one TITLE (minOccurs=”1” maxOccurs=”1”) 2. At least one, and possibly a great many, COMPOSERs (minOccurs=”1” maxOccurs=”unbounded”) 3. Any number of PRODUCERs, although possibly no producer at all (minOccurs=”0” maxOccurs=”unbounded”) 4. Either one PUBLISHER or no PUBLISHER at all (minOccurs=”0” maxOccurs=”1”) 5. Exactly one LENGTH (minOccurs=”1” maxOccurs=”1”) 6. Exactly one YEAR (minOccurs=”1” maxOccurs=”1”) 7. At least one ARTIST, possibly more (minOccurs=”1” maxOccurs=”unbounded”) 8. An optional PRICE, (minOccurs=”0” maxOccurs=”1”)

22 Complex Types cont… 22 This is much more flexible and easier to use than the limited ?, *, and + that are available in DTDs If minOccurs and maxOccurs are not present, the default value of each is 1

23 Complex Types cont… 23 Element content When elements contain other elements Listing 20-9

24 Complex Types cont… 24 Element Content Hot Cop Jacques Morali Henri Belolo Victor Willis Jacques Morali PolyGram Records 6:20 1978 Village People Hot Cop Jacques Morali Henri Belolo Victor Willis Jacques Morali PolyGram Records 6:20 1978 Village People

25 Complex Types cont… 25 Sharing content models Hot Cop Jacques Morali Henri Belolo Victor Willis Jacques Morali PolyGram Records 6:20 1978 Village People Hot Cop Jacques Morali Henri Belolo Victor Willis Jacques Morali PolyGram Records 6:20 1978 Village People

26 Complex Types cont… 26 Mixed Content Mr. Jacques Morali Esq. Mr. Henri L. Belolo, M.D. Mr. Victor C. Willis Mr. Jacques S. Morali Mr. Jacques Morali Esq. Mr. Henri L. Belolo, M.D. Mr. Victor C. Willis Mr. Jacques S. Morali

27 Complex Types cont… 27 Mixed Content de

28 Simple Types 28 xsd:gYear and xsd:duration These declarations say that it’s no longer okay for the YEAR and LENGTH elements to contain just any old string of text Instead, they must contain strings in particular formats <xsd:element name=”ARTIST” type=”xsd:string” maxOccurs=”unbounded”/> <xsd:element name=”PRICE” type=”xsd:string” minOccurs=”0”/> <xsd:element name=”ARTIST” type=”xsd:string” maxOccurs=”unbounded”/> <xsd:element name=”PRICE” type=”xsd:string” minOccurs=”0”/>

29 29

30 30

31 Simple Types 31 There are 44 built-in simple types in the W3C XML Schema Language These can be unofficially divided into seven groups ✦ Numeric types ✦ Time types ✦ XML types ✦ String types ✦ The boolean type ✦ The URI reference type ✦ The binary types Go to the Book for Examples

32 Attributes 32

33 references 33 Schema http://www.w3schools.com/schema/ Attribute http://www.w3schools.com/schema/schema_simple_attri butes.asp


Download ppt "XML SCHEMA 1 CH 20. Objective 2 What’s wrong with DTDs? What is a schema? The W3C XML Schema Language Hello schemas Complex types Simple types Deriving."

Similar presentations


Ads by Google