170 likes | 345 Views
More on XML XML Schema Definition Language (XSD). XML Schema Definition Language (XSD). Introduced in 2001 as a standard by W3C organization. Defines the XML schema, the base for all XML “languages” such as WSDL, WSDD, … Defines a set of predefined (built-in) types such as int, string.
E N D
XML Schema Definition Language (XSD) • Introduced in 2001 as a standard by W3C organization. • Defines the XML schema, the base for all XML “languages” such as WSDL, WSDD, … • Defines a set of predefined (built-in) types such as int, string. • Provides a means of defining new data types. • Describes the structure of XML documents.
Compare to a programming language, say Java. XML Schema Definition Language. XSD Compare to Java class definitions used for a particular application. An XML schema for a particular application. Example WSDL schema Compare to an object instance from above class Example WSDL document for a service A document conforming to a particular schema
Standard data types Correspond to “primitive” datatypes in a high level language. Specific sizes and form. Example type = xsd:int Such attributes would appear in an XML document to define the types of operands used when a a service is invoked.
In an WSDL document, datatypes would appear in the message definitions: <wsdl:message name="squaredRequest"> <wsdl:part name="in0" type="xsd:int"/> </wsdl:message>
Complex datatypes • Used to represent structured datatypes, similar to that of high level language. • A structure is defined consisting of defined datatypes. Example <complexType name=“student”> <sequence> <element name=StudentName” type=“xsd:string”/> <element name=“StudentID” type=“xsd:int”/> <element name=“Login” type=“xsd:string”/> </sequence> </complexType>
Derived datatypes • Can “derive data types from “primitive” datatypes, using one of three mechanisms, restriction, extension, and list. Example • Can restrict a datatype to have certain values.
From http://www.w3.org/ Built-in Built-in derived
XML namespaces • Purpose to prevent naming collisions in elements and attribute names1. Must be a URI (often a URL), but only used as unique string. Example of a default namespace xmlns=“http://www.w3.org/2001/XMLSchema” Example of a namespace applied to certain names (using prexfix myns) xmlns:myns=“http://www.cs.uncc.edu/~abw/ns” 1. “Real World XML Web Services: For VB and VB .net Deveopers” by Y. Shohoud, online on http://www.learnxmlws.com.
Assignment 1 WSDL example <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Assignment 1 WSDL example <wsdl:definitions . . . xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdl=“http://schemas.xmlsoap.org/wsdl/” xmlns:wsdlsoap=“http://schemas.xmlsoap.org/wsdl/soap/” xmlns:xsd="http://www.w3.org/2001/XMLSchema" . . . >
WSDL file for myMath service Namespaces <wsdl:message name="squaredRequest"> <wsdl:part name="in0" type="xsd:int"/> </wsdl:message> <wsdl:message name="squaredResponse"> <wsdl:part name="squaredReturn" type="xsd:int"/> </wsdl:message> <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> Message definitions <wsdl:portType name="MyMath"> <wsdl:operation name="squared" parameterOrder="in0"> <wsdl:input message="impl:squaredRequest" name="squaredRequest"/> <wsdl:output message="impl:squaredResponse" name="squaredResponse"/> </wsdl:operation> </wsdl:portType> portType <wsdl:binding name="MyMathSoapBinding" type="impl:MyMath"> <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="squared"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="squaredRequest"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://DefaultNamespace" use="encoded"/> </wsdl:input> <wsdl:output name="squaredResponse"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://DefaultNamespace" use="encoded"/> </wsdl:output> </wsdl:operation> </wsdl:binding> Bindings Service definitions <wsdl:service name="MyMathService"> <wsdl:port binding="impl:MyMathSoapBinding" name="MyMath"> <wsdlsoap:address location="http://localhost:8080/axis/testaccount/ MyMath"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
Sample places for WSDL namespace xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" <wsdl:binding name="MyMathSoapBinding" type="impl:MyMath"> <wsdlsoap:binding style="rpc“ transport= "http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="squared"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="squaredRequest"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> </wsdl:input> <wsdl:output name="squaredResponse"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> </wsdl:output> </wsdl:operation> </wsdl:binding>
Sample places for SOAP namespace xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" <wsdl:binding name="MyMathSoapBinding" type="impl:MyMath"> <wsdlsoap:binding style="rpc“ transport= "http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="squared"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="squaredRequest"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> </wsdl:input> <wsdl:output name="squaredResponse"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> </wsdl:output> </wsdl:operation> </wsdl:binding>
More on schemas • One can create your own schema to match your web service application. Example Suppose you want to have purchase order system, with a schema for the invoices.
Invoice schema <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.xmltc.com/railco/invoice/schema/"> <xsd:element name="InvoiceType"> <xsd:complexType> <xsd:sequence> <xsd:element name="Number" type="xsd:integer"/> <xsd:element name="Total" type="xsd:double"/> <xsd:element name="Date" type="xsd:date"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> Could save as file “Invoice.xsd”
Purchase order <definitions name="InvoiceProcessing" … namespaces <types> <xsd:schema targetNamespace="http://www.xmltc.com/railco/invoiceservice/schema/"> <xsd:import namespace="http://www.xmltc.com/railco/invoice/schema/" schemaLocation="Invoice.xsd"/> <xsd:element name="SubmitInvoiceType"> <xsd:complexType> <xsd:sequence> <xsd:element name="ContextID" type="xsd:integer"/> <xsd:element name="InvoiceLocation" type="xsd:string"/> <xsd:element name="InvoiceDocument" type="inv:InvoiceType"/> </xsd:sequence> </xsd:complexType> </xsd:element> /xsd:schema> </types> <message name="receiveSubmitMessage"> <part name="RequestParameter" element="invs:SubmitInvoiceType"/> </message> <portType name="InvoiceProcessingInterface"> <operation name="Submit"> <input message="tns:receiveSubmitMessage"/> </operation> </portType> … bindings and sercive/ports </definitions>