quick intro to xml schemas & soap - world wide web ... · quick intro to xml schemas & soap...

26
Quick Intro to Quick Intro to XML Schemas & SOAP XML Schemas & SOAP Noah Mendelsohn Noah Mendelsohn Lotus Development Corp. Lotus Development Corp. Oct. 12, 2000 Oct. 12, 2000

Upload: vokien

Post on 16-May-2018

232 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Quick Intro to Quick Intro to XML Schemas & SOAPXML Schemas & SOAP

Noah MendelsohnNoah MendelsohnLotus Development Corp.Lotus Development Corp.Oct. 12, 2000Oct. 12, 2000

Page 2: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

How SOAP uses SchemasHow SOAP uses Schemas

To define SOAP's XML vocabularyTo define SOAP's XML vocabulary

Optionally: to define your msg. vocabularyOptionally: to define your msg. vocabulary

SOAP encoding uses schema "types"SOAP encoding uses schema "types"Schema builtin datatypes: integer, float, date, etc.Schema builtin datatypes: integer, float, date, etc.SOAP builtins for arrays & structsSOAP builtins for arrays & structsTypes you define in schemaTypes you define in schemaYou can indicate types:You can indicate types:

Directly in your message using xsi:typeDirectly in your message using xsi:typeOptionally: in an external schema documentOptionally: in an external schema document

Page 3: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Schema WG StatusSchema WG Status

Hope for candidate recommendation soonHope for candidate recommendation soon

Three documentsThree documentsStructures: the overall languageStructures: the overall languageDatatypes: integer, float, date, etc.Datatypes: integer, float, date, etc.Primer: start with this!Primer: start with this!

Public working drafts availablePublic working drafts available

Page 4: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

A SchemaA Schema

<xsd:schema xmlns:xsd="..." targetNamespace="yourURI"> <xsd:element name="purchaseOrder" type="POType"/> <xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="POType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType>

........</xsd:schema>

Page 5: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Namespaces and Schema Documents

Page 6: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

One Schema Doc per NamespaceOne Schema Doc per Namespace

<xsd:schema xmlns:xsd="..." targetNamespace="yourURI"> <xsd:element name="purchaseOrder" type="POType"/> <xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="POType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType>

........</xsd:schema>

Validates:

<po:purchaseOrder xmlns:po="yourURI">....

</po:purchaseOrder>

Page 7: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

A SOAP MessageA SOAP Message

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://{soaporg}/envelope/" SOAP-ENV:encodingStyle= "http://{soaporg}/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

Page 8: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

SOAP SchemaSOAP Schema

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://{soaporg}/envelope/" SOAP-ENV:encodingStyle= "http://{soaporg}/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

soapenv.xsd: validates SOAP's vocabulary

Page 9: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

SOAP Schema & User SchemaSOAP Schema & User Schema

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://{soaporg}/envelope/" SOAP-ENV:encodingStyle= "http://{soaporg}/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

soapenv.xsd stockquote.xsd

Page 10: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Declaring Elements and Attributes

Page 11: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

A Sample InstanceA Sample Instance<?xml version="1.0"?><purchaseOrder orderDate="1999-10-20"> <shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street> <city>Mill Valley</city> <state>CA</state> <zip>90952</zip> </shipTo> <billTo country="US">...</billTo> <comment>Hurry, my lawn is going wild!</comment> <items> <item partNum="872-AA">...</item> <item partNum="926-AA">...</item> </items></purchaseOrder>

Page 12: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

A SchemaA Schema

<xsd:schema xmlns:xsd="..." targetNamespace="yourURI"> <xsd:element name="purchaseOrder" type="POType"/> <xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="POType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType>

........</xsd:schema>

Page 13: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Elements have TypesElements have Types

<xsd:schema xmlns:xsd="..." targetNamespace="yourURI"> <xsd:element name="purchaseOrder" type="POType"/> <xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="POType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType>

........</xsd:schema>

Page 14: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Elements have TypesElements have Types

<xsd:schema xmlns:xsd="..." targetNamespace="yourURI"> <xsd:element name="purchaseOrder" type="POType"/> <xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="POType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType>

........</xsd:schema>

Built in types

Page 15: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Elements have TypesElements have Types

<xsd:schema xmlns:xsd="..." targetNamespace="yourURI"> <xsd:element name="purchaseOrder" type="POType"/> <xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="POType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType>

........</xsd:schema>

User-defined Types

Page 16: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Global elementsGlobal elements

<xsd:schema xmlns:xsd="..." targetNamespace="yourURI"> <xsd:element name="purchaseOrder" type="POType"/> <xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="POType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType>

........</xsd:schema>

Global elements useable

anywhere

Page 17: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Locally scoped elementsLocally scoped elements

<xsd:schema xmlns:xsd="..." targetNamespace="yourURI"> <xsd:element name="purchaseOrder" type="POType"/> <xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="POType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType>

........</xsd:schema>

Locally scoped

elements useable only

in parent type

Page 18: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Attributes have TypesAttributes have Types

<xsd:schema xmlns:xsd="..." targetNamespace="yourURI"> <xsd:element name="purchaseOrder" type="POType"/> <xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="POType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType>

........</xsd:schema>

Page 19: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Simple and Complex Types

Page 20: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Attributes

width="10"

Simple typesSimple types

height="20"

Page 21: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Attributes

width="10"

Simple typesSimple types

height="20"

Same restriction on content = "type"

(xsd:integer)

Page 22: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Attributes

width="10"

Simple typesSimple types

height="20"

<width> 10</width>

Elements

<height> 20</height>

Simple type captures what's common:It's an integerType has a name (xsd:integer)Simple types work on attrs and elements

Page 23: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Types for ElementsTypes for Elements

<width> 10</width>

Simple type

<height> 20</height>

<width unit="cm"> 10</width>

Complex type<height unit="cm"> 20</height>

Type(s) capture what's common:It's an integer + attributeType has a name (yourns:measure)

Page 24: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

More Complex Types for ElementsMore Complex Types for Elements

<ShipTo> <street>1 Main St.</street> <city state="NY">Albany</city></ShipTo>

Element

<BillTo> <street>13 Market St.</street> <city state="CA">San Jose</city></BillTo>

Complex types are for elements:Sharing content models, attr lists.Type has a name (somens:address)

Page 25: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Self-describing SOAP MsgsSelf-describing SOAP Msgs

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://{soaporg}/envelope/" SOAP-ENV:encodingStyle= "http://{soaporg}/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol xsi:type="xsd:string"> DIS </symbol>

<quoteDate xsi:type="xsd:date"> 1999-05-21

</quoteDate> </m:GetLastTradePrice> </SOAP-ENV:Body></SOAP-ENV:Envelope>

Page 26: Quick Intro to XML Schemas & SOAP - World Wide Web ... · Quick Intro to XML Schemas & SOAP Noah Mendelsohn Lotus Development Corp. Oct. 12, 2000

Summary: Summary: How SOAP uses SchemasHow SOAP uses Schemas

To define SOAP's XML vocabularyTo define SOAP's XML vocabulary

Optionally: to define your msg. vocabularyOptionally: to define your msg. vocabulary

SOAP encoding uses schema "types"SOAP encoding uses schema "types"Schema builtin datatypes: integer, float, date, etc.Schema builtin datatypes: integer, float, date, etc.SOAP builtins for arrays & structsSOAP builtins for arrays & structsTypes you define in schemaTypes you define in schemaYou can indicate types:You can indicate types:

Directly in your message using xsi:typeDirectly in your message using xsi:typeOptionally: in an external schema documentOptionally: in an external schema document