Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.

Similar presentations


Presentation on theme: "ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada."— Presentation transcript:

1 ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada

2 Web Services-Content  Introduction to XML  DTDs and XML Schema  Web Services, SOAP, WSDL, VoiceXML 2

3 Unit 1. Introduction to XML  Learning Objectives  Understand how XML is different from HTML  Understand the basic things that make up XML 3

4 What is XML?  XML - EXtensible Markup Language  It is a meta-markup language  Let’s create our own tags  Ex: John  It is a standard for data structuring and interchange  It is surrounded by TLAs: XSL, DTD, SAX, DOM… and FRLAs: XSLT, VXML, SOAP…  Descends from SGML 4

5 5 XML is a Meta-Language (from w3c site)

6 6 XML is about Structured Data  Unstructured data-natural language description: ”A company has a personnel and the personnel has one or more persons. Persons have name, address, etc…”  Structured data: a tree personnel person name title givenfamily address street Mr. John Higgins zip M3C1H7 person Wall St. company

7 7 Why not HTML?  HTML tags are concerned with rendering  XML is concerned with the semantic of information  XML is a meta-language, HTML can be seen as an instance of it (XHTML)  HTML is one of the presentation formats for XML languages

8 8 Simple HTML document(1 of 2) Helm Brown Moon Light Toronto

9 9 Simple HTML document (2 of 2)  An HTML browser knows how to render  A human can understand each line, can a computer or application?  How easy is to search for a piece of data?

10 10 Simple XML (PML?) Mr. Helm Brown Moon Light M3C1H7

11 11 Tags, Elements, CDATA Mr. Helm Brown Moon Light M3C1H7 Start tag Element End tag CDATA Markup

12 12 XML Document as a Tree person name titlefamilygiven address street Mr.HelmBrown zip M3C1H7 Moon Light parent children CDATA

13 13 XML Attributes  Attributes are properties of the element  Pairs of (name, value), within the element  Values are between quotation marks …. Attributes

14 14 Well Formed Documents  An XML document is well formed if obeys a set of rules 1.Tags cannot be inferred; they must be explicit. All starting tags must have corresponding ending tags. All ending tags must have corresponding starting tags 2.Empty tags need a Slash ( /) before the closing Greater Than (>) character: 3.All attribute values must be enclosed in either single or double quotation marks 4.Tags must nest correctly: 5.Tags are case sensitive and must match each other in every implementation

15 15 Namespaces in XML  Distinguish between elements and attributes from different XMLs  Qualified name = prefix:local  Prefix is the Namespace  Local identifies the particular element 1.xmlns:cmp=http://www.XML.org/company xmlns:lb=http://www.XML.org/library 2. Ms … As You Like It Qualified name

16 16 More in XML Documents  Empty elements: no children  Comments  Processing Instructions  Entities  Further readings  http://www.w3.org

17 17 XML for Presentation XML doc Presen- tation Voice XML WML HTML, PDF,PS

18 18 XML for Communication Appli- cation A Appli- cation A Appli- cation 1 Appli- cation 1 Appli- cation B Appli- cation B Appli- cation 2 Appli- cation 2 Transfor- mation 1 Transfor- mation 1 Transfor- mation 2 Transfor- mation 2 XML 1 XML 2 XML

19 19 XML for Web Services APP A APIAPI APP B APIAPI XML getAPI() XML RPC (SOAP) 1 2 3 3

20 20 Summary  We learned:  XML is a vehicle for representing structured data  XML allows you to create your own language (data format)  An XML document contains start tags, end tags, elements and attributes, CDATA  Elements: parent, children, root element, document element

21 21 Exercise (10 min.)  Write an XML document for the course you are attending:  title: XML and Related Technologies  description: basics of XML and related technologies  instructor  Name: Marin Litoiu  Affiliation: CAS  Participants  Participant:  name: John Trevis  job: software programmer  Participant  Name: Big Boss  Job: manager  …..…….  View the document with IExplorer

22 22 Quiz(1)  Which statement(s) is(are) false?: 1.XML makes data interchange easy 2.XML is a standard 3.XML is a meta-language 4.An well-formed XML document has nested tags and is a tree 5.An empty element has no attributes  True or false? 1.XML is a protocol, like HTTP, IIOP and RMI 2.You can have rendering tags in XML documents 3.Attributes for Elements are like parts to whole 4.XML isolates the presentation from content

23 23 Quiz(2)  XML is not a language and has not recognized tags. Rather, it is a meta- language that allows you to define your own language 1.True 2. False  Which of the following is not a rule for creating well-formed documents in XML? 1.All start tags must have corresponding ending tags 2.Empty tags need a Slash (/) before the closing Greater Than (>) character. 3.All attribute values must be enclosed in brackets 4.Tags must nest correctly 5.Tags are case sensitive and must match each other in every implementation.

24 24 Unit 2. DTDs  Learning Objectives  What is DTD  Why we need DTD  How to write a DTD

25 25 Document Type Definition(DTD)  DTD defines the grammar for XML docs  Tag names  How elements can be nested  If the elements may, must appear  How often the elements appear  Attributes of the elements  Default values for the attributes  All valid values for the attributes

26 26 Valid documents  The XML document contains information about its dtd  Exemple:  A valid XML document follows the syntax defined in its dtd  An XML parser will check the validity of the XML document against its dtd  Any XML editor has an XML parser  Eclipse has an XML Editor

27 27 XML Documents and DTD author.dtd author1.xmlauthor3.xml author2.xml author.class One editor One parser Many XMLs …….. One DTD

28 28 Simple person.dtd

29 29 Element definition ……. Element name Children Element declaration Element Type

30 30 Attributes in DTD DTD XML El. name Attr. name Attr type Default value

31 31 Empty Elements  No children, no start or end tag DTD XML

32 32 Attributes Types  CDATA “Eglinton East”  NMTOKEN (name token):  ID: unique Id within a document  IDREF: a reference to an ID  IDREFS: many IDREF  ENUMERATION: (a|b|c|d)  ENTITY: reference to an external unparsed entity  ENTITIES: many ENTITY

33 33 ID and IDREF  DTD:  XML:

34 34 Default values for attributes  #REQUIRED - a value MUST be provided  #IMPLIED – optional value  [#FIXED] “value”, if no value is provided, the “value” should be used

35 35 Child Element Occurrences  “A man has zero or one wives, zero or more children and speaks one or more languages”   ? zero or one times  * zero or more times  + one or more times , sequence  | or- choice

36 36 Summary of Unit 2  We learned:  DTD is the grammar for XML documents  DTD defines: elements (parents and children), attributes, default and allowed values  DTDs are agreed upon by a community  Valid XML documents obey the structure of DTD

37 37 Exercise 1  Write an XML Document for person.dtd from slide 28  Validate the document with Internet Explorer  make sure you specify the SYSTEM dtd  You can use an XML Editor  For example, Eclipse has editors for XML, DTD and XML Schema.

38 38 Quiz  Which statement(s) is(are) false 1.DTD is a grammar for XML documents 2.IDREF is an attribute type and it means a reference to an attribute called “ID” 3. defines an element x with zero or more children elements y 4. defines an attribute z for the element y. z can have 1 or 2 characteristics, preferably 2. 5. is a valid comment 6. defines an empty element bag

39 39 Unit 3. XML Schema  Learning Objectives  Why we need XML Schema  How to write an XML Schema  When to use XML Schema

40 40 XML Schema  DTD has few predefined types  DTD syntax is different from XML syntax  DTD cannot express certain constraints: “c occurs 3 to 5 times”  XML Schema to the rescue  Describes and constrains the content of XML  Defines simple data types and ways to derive new simple or complex types  Link: www.w3.org/XML/Schemawww.w3.org/XML/Schema  Namespace: xmlns:xsd='http://www.w3.org/20001/XMLSchema'

41 XML Schema structure  Schema element: the top level element ( as per XML definition)  Element—defines the elements that will show up in your XML doc  Simple type elements: simple elements derived from predefined elements in XML schema  Complex type elements: complex data types ( sequence, union..) Example ………………….. © Marin Litoiu, York University, Canada

42 42 XML Schema uses XML Syntax DTD XML Schema XML attributes ??? XML Elements

43 43 All Built in Types

44 Simple types(1) http://www.w3.org/TR/xmlschema-0/#ref18 Simple TypeExamples (delimited by commas)Notes stringThis is a string normalizedStringThis is a stringNL and CR are converted to spaces tokenThis is a stringTrailing and leading spaces are removed integer...-1, 0, 1,... integer is ·derived· from decimal by fixing the value of ·fractionDigits· to be 0and disallowing the trailing decimal point. ·derived·decimal·fractionDigits· positiveInteger1, 2,... negativeInteger... -2, -1 nonNegativeInteger0, 1, 2,... nonPositiveInteger... -2, -1, 0 long -9223372036854775808,... -1, 0, 1,... 9223372036854775807 unsignedLong0, 1,... 18446744073709551615 int -2147483648,... -1, 0, 1,... 2147483647 int is ·derived· from long by setting the value of ·maxInclusive· to be 2147483647 and ·minInclusive· to be -2147483648. ·derived·long·maxInclusive· minInclusive· unsignedInt0, 1,...4294967295 short-32768,... -1, 0, 1,... 32767 unsignedShort0, 1,... 65535 byte-128,...-1, 0, 1,... 127 unsignedByte0, 1,... 255

45 Simple types(2) http://www.w3.org/TR/xmlschema-0/#ref18 decimal-1.23, 0, 123.4, 1000.00 float -INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN equivalent to single-precision 32-bit floating point, NaN is "not a number", INF-inifinite double -INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN equivalent to double-precision 64-bit floating point booleantrue, false, 1, 0 durationP1Y2M3DT10H30M12.3S 1 year, 2 months, 3 days, 10 hours, 30 minutes, and 12.3 seconds dateTime1999-05-31T13:20:00.000-05:00 May 31st 1999 at 1.20pm Eastern Standard Time which is 5 hours behind Co-Ordinated Universal Time date1999-05-31 time13:20:00.000, 13:20:00.000-05:00 gYear19991999, g stands for Gregorian calendar gYearMonth1999-02 the month of February 1999, regardless of the number of days, gMonth--05May, regardless of year, day gMonthDay--05-31every May 31st gDay---31the 31st day

46 Examples  XML Schema  XML Document John 2001-01-01 9 2011-01 © Marin Litoiu, York University, Canada

47 Questions  How do I specify this structure of the XML elements? John Smith  See next slide… © Marin Litoiu, York University, Canada

48 48 Complex Types in XML Schema: Sequence  Create once, use many times as a template  High reusability, easy maintainability 1. Types --------------------------- 2. Elements ----------------------------------- 3. This how they will look in XML documents John Smith Bill Gates Is like “, “ in dtd

49 Validating XMLs and XML schemas  Schema, in a file named name.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Quiz" xmlns:tns="http://www.example.org/Quiz" elementFormDefault="qualified">  XML file: references the file name.xsd <employeeName xmlns="http://www.example.org/Quiz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/Quiz name.xsd "> Bill Gates © Marin Litoiu, York University, Canada

50 Quiz (10 min) 1. Write a valid xml document for this xml schema <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Quiz" xmlns:tns="http://www.example.org/Quiz" elementFormDefault="qualified"> 2. Write a simplified version of this XML schema (condense the types) 3. Write an XML document for the new schema © Marin Litoiu, York University, Canada

51 Complex Types: Choice …..  Only one of those: USAddress or CAAddress will show up in an instance XML document  The address is followed by the items (items type is Items) © Marin Litoiu, York University, Canada

52 52 Anonymous Types  Anonymous type does not have name, it is a private child of the element it types Anonymous type

53 53 Attributes  Attributes have name, value, type  They are children of the element ……….

54 54 Occurrence Constraints  Occurrence Constraints for Children Elements  minOccurs, maxOccurs Ex:  Constraints for Attributes  use, value Ex:

55 55 Derived Types-Pattern  “Phone number has an optional country code, an area code of tree digits, a hyphen, and 7 digits”  Use pattern

56 56 Derived Types-Interval  “age is an integer greater that 10, less than 121”

57 57 Derived Types- Enumeration  Enumerations are simple types

58 Derived types: Extension http://www.w3.org/TR/xmlschema-0/#po.xsd

59 59 DTD or XML Schema  For reach type documents, with many types and constrains, use XML schemas  Use DTD when  Want a compact representation  Not interested in semantic of the grammar, just in structure

60 60 Summary  We learned:  XML Schema is a replacement for DTD  Has a syntax similar to XML  Allows the user to  Specialize by extension and restriction basic simple types  Define his/her own complex types

61 Exercise (10 min). 1.For the po.xsd schema from http://www.w3.org/TR/xmlschema-0/#po.xsd, write a sample xml document ( should be different from the one on web site)http://www.w3.org/TR/xmlschema-0/#po.xsd

62 62 Quiz  True of false? 1.XML schemas are more compact that DTDs 2.To define complex types, one should use tag 3.Declaration is incorrect because is does not specify the name of the element y belongs to 4.“restriction” is a specialization mechanism in XML schema that constrains a “base” type 5.The user can only create complex types but cannot create simple types 6.“enumeration” is a simple type


Download ppt "ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada."

Similar presentations


Ads by Google