Schemas and Soap PRT
Schemas and Soap PRT
Noah Mendelsohn
Lotus Development Corp.
Oct. 12, 2000
How SOAP uses Schemas
To define SOAP's XML vocabulary
Optionally: to define your msg. vocabulary
SOAP encoding uses schema "types"
Schema builtin datatypes: integer, float, date, etc.
SOAP builtins for arrays & structs
Types you define in schema
You can indicate types:
Directly in your message using xsi:type
Optionally: in an external schema document
Schema WG Status
<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>
Namespaces and
Schema Documents
One 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">
Validates:
<xsd:sequence>
<xsd:element name="shipTo" type="USAddress"/>
<xsd:element name="billTo" type="USAddress"/>
<po:purchaseOrder
<xsd:element ref="comment" minOccurs="0"/>
xmlns:po="yourURI">
<xsd:element name="items" type="Items"/>
</xsd:sequence>
....
<xsd:attribute name="orderDate" type="xsd:date"/>
</po:purchaseOrder>
</xsd:complexType>
........
</xsd:schema>
A 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>
SOAP Schema
soapenv.xsd: validates SOAP's vocabulary
<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>
SOAP Schema & User Schema
soapenv.xsd stockquote.xsd
<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>
Declaring Elements and
Attributes
A 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>
A 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>
Elements 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>
Elements 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"/>
Built in
<xsd:element name="billTo" type="USAddress"/>
types
<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>
Elements 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"/>
User-defined
<xsd:element ref="comment" minOccurs="0"/>
Types
<xsd:element name="items" type="Items"/>
</xsd:sequence>
<xsd:attribute name="orderDate" type="xsd:date"/>
</xsd:complexType>
........
</xsd:schema>
Global 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>
Global
<xsd:attribute name="orderDate" type="xsd:date"/>
</xsd:complexType>
elements
........ useable
</xsd:schema> anywhere
Locally scoped elements
Locally
<xsd:schema xmlns:xsd="..." targetNamespace="yourURI">
scoped
<xsd:element name="purchaseOrder" type="POType"/>
elements
<xsd:element name="comment" type="xsd:string"/>
useable only
<xsd:complexType name="POType"> in parent
<xsd:sequence> type
<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>
Attributes 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>
Simple and Complex
Types
Simple types
Attributes
width="10" height="20"
Simple types
Attributes
width="10" height="20"
Same restriction on
content = "type"
(xsd:integer)
Simple types
Attributes
width="10" height="20"
Elements
<width> <height>
10 20
</width> </height>
<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>
Summary:
How SOAP uses Schemas
To define SOAP's XML vocabulary
Optionally: to define your msg. vocabulary
SOAP encoding uses schema "types"
Schema builtin datatypes: integer, float, date, etc.
SOAP builtins for arrays & structs
Types you define in schema
You can indicate types:
Directly in your message using xsi:type
Optionally: in an external schema document