xml and web services cs409 application services even semester 2007
TRANSCRIPT
![Page 1: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/1.jpg)
XML and Web Services
CS409 Application ServicesEven Semester 2007
![Page 2: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/2.jpg)
2
XML Primer
• Extensible Markup Language was introduced in 1998.
• Similar to HTML, but contains an infinite set of elements and attributes.
• All key web services technology are based on XML.
![Page 3: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/3.jpg)
3
Document-Centric XML
• Content is typically meant for human consumption.
• Used to mark up semi structured document.
• Mark up is used to present the information rather than to describe it.
![Page 4: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/4.jpg)
4
Document-Centric XML (2)
• Example, a user guide:<H1>Skateboard Usage Requirements</H1>
<P>To use the <B>SuperFast</B> skateboard you have to have:</P>
<LIST>
<ITEM>A <U>strong</U> pair of legs.</ITEM>
<ITEM>Reasonably long stretch of road surface.</ITEM>
<ITEM>Impulse to <I>impress</I> others.</ITEM>
</LIST>
<P>If you have all of the above, you can proceed to:
<LINK HREF=“Chapter2.xml”>Getting Started</LINK></P>
![Page 5: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/5.jpg)
5
Data-Centric XML
• Content is typically meant for machine consumption.
• Used to mark up highly structured information.
• Includes many types of tags, organized in a highly-structured manner.
• Order and positioning of tags matter, relative to other tags.
![Page 6: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/6.jpg)
6
Data-Centric XML (2)
• Example, a purchase order:<po id=“43871” submitted=“2006-02-01” customerId=“73852”> <billTo> <company>The Soup Restaurant</company> <street>One Microsoft Way</street> <city>Redmond</city> <state>Washington</state> <zipcode>01567</zipcode> </billTo> <order> <item sku=“318-ABC” quantity=“8”> <description>Tall beer glass, plain style</description> </item> <item sku=“898-DEL” quantity=“9”> <description>Table cloth</description> </item> <item sku=“988-MHH” quantity=“600” /> </order></po>
![Page 7: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/7.jpg)
7
XML Standards for Web Services
• XML instances– Rules for creating syntactically correct XML.
• XML Schema– Enables detailed validation and specification of its data
types.
• XML Namespaces– Mechanisms for combining multiple sources XML in a
single document.
• XML processing– Creating, parsing, and manipulating XML from
programming languages.
![Page 8: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/8.jpg)
8
XML Instances
• Anatomy of instance:– Declaration– Comments– Elements– Attributes– CDATA section
![Page 9: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/9.jpg)
9
XML Instance (2)
• Declaration– Describe the version of XML.– Defined the character encoding.
• Comments– Will be ignored by processing application.
• Example:<?xml version=“1.0” encoding=“UTF-8”>
<!-- Created by Doddy Lukito for example only --><po id=“43871” submitted=“2006-02-01” customerId=“73852”>
<!-- The rest of the contents are similar to previous example -->
</po>
![Page 10: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/10.jpg)
10
XML Instance (3)
• Elements– Everything between the pairing of start tag and
end tag.– Content types
• Element-only content, consists entirely of nested elements.
• Mixed content, consists of nested elements and text.
• Empty content, start tag immediately followed by end tag.
![Page 11: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/11.jpg)
11
XML Instance (4)
• Attributes– A name value pair for the element.– Must use equal sign (=) followed by quote
value.– Attributes begin with xml: is reserved for XML
specification.
• Example<po id=“43871” submitted=“2006-02-01” customerId=“73852”>
<order>
<item sku=“318-ABC” quantity=“8”>
<description xml:lang=“en”>Tall beer glass, plain style</description>
![Page 12: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/12.jpg)
12
XML Instance (5)
• CDATA section– Mark a section of text as literal, so it won’t be
parsed as tags and symbols.– The section will be treated as a string of
characters.
• Example:<![CDATA [ <HTML> <BODY> <P>Please don’t treat this as <B>tags</B> but just <U>literal</U></P> </BODY> </HTML>]]>
![Page 13: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/13.jpg)
13
XML Namespaces
• Created to solve recognition and collision problem in XML.
• Is an additional identifier for XML element within a document.
• Namespaces uses Uniform Resource Identifiers (URIs) as identifier.
![Page 14: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/14.jpg)
14
XML Without Namespaces<message from=“[email protected]” to=“[email protected]” sent=“2006-02-01”>
<attachment>
<description>The Purchase Order</description>
<item>
<po id=“43871” submitted=“2006-02-01” customerId=“73852”>
<billTo>
<company>The Soup Restaurant</company>
<street>One Microsoft Way</street>
<city>Redmond</city>
<state>Washington</state>
<zipcode>01567</zipcode>
</billTo>
<order>
<item sku=“318-ABC” quantity=“8”>
<description>Tall beer glass, plain style</description>
</item>
</order>
</po>
</item>
</attachment>
</message>
![Page 15: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/15.jpg)
15
XML With Namespaces<message from=“[email protected]” to=“[email protected]” sent=“2006-02-01” xmlns=“http://www.xcommerce.com/ns/message”> <attachment> <description>The Purchase Order</description> <item> <po:po id=“43871” submitted=“2006-02-01” customerId=“73852” xmlns:po=“http://www.doddystore.com/ns/po”> <billTo> <company>The Soup Restaurant</company> <street>One Microsoft Way</street> <city>Redmond</city> <state>Washington</state> <zipcode>01567</zipcode> </billTo> <order> <item sku=“318-ABC” quantity=“8”> <description>Tall beer glass, plain style</description> </item> </order> </po:po> </item> </attachment></message>
![Page 16: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/16.jpg)
16
XML Schemas
• A meta-language to describe– the structure of XML document.– the mapping of XML syntax to data type.
• Offer an automated an declarative mechanism to validate the contents of XML documents as they are parsed.
• The final specification is defined by the W3C in 2001.
![Page 17: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/17.jpg)
17
Basic XML Schema Structure
<?xml version=“1.0” encoding=“UTF-8”>
<xsd:schema xmlns=“http://www.doddystore.com/ns/po”
xmlns:xsd=“http://www.w3.org/2001/XMLSchema”
targetNamespace=“http://www.doddystore.com/ns/po”
<xsd:anotation>
<xsd:documentation xml:lang=“en”>
Purchase order schema for Doddy’s online store
</xsd:documentation>
</xsd:annotation>
<xsd:complexType name=“billTo”>
<xsd:sequence>
<xsd:element name=“company” type=“xsd:string” />
<xsd:element name=“street” type=“xsd:string” />
<xsd:element name=“city” type=“xsd:string” />
<xsd:element name=“state” type=“xsd:string” />
<xsd:element name=“zipcode” type=“xsd:integer” />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
![Page 18: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/18.jpg)
18
Associating Schema to Document
<?xml version=“1.0” encoding=“UTF-8”>
<po:po xmlns:po=“http://www.doddystore.com/ns/po”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://www.doddystore.com/ns/po
http://www.doddystore.com/schema/po.xsd”
id=“43871” submitted=“2006-02-01” customerId=“73852”
<billTo>
<company>The Soup Restaurant</company>
<street>One Microsoft Way</street>
<city>Redmond</city>
<state>Washington</state>
<zipcode>01567</zipcode>
</billTo>
<order>
<item sku=“318-ABC” quantity=“8”>
<description>Tall beer glass, plain style</description>
</item>
</order>
</po:po>
![Page 19: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/19.jpg)
19
XML Schemas Simple Type
• Sets of predefined basic data types.
• String, base64binary, hexBinary, integer, positiveInteger, negativeInteger, nonNegativeInteger, nonPositiveInteger, decimal, boolean, time, dateTime, duration, date, Name, Qname, anyURI, ID, IDREF.
![Page 20: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/20.jpg)
20
XML Schemas Simple Type (2)
• Characteristics of simple type (facets):– Length, minLength, maxLength, pattern,
enumeration, whiteSpace, minInclusive, maxInclusive, minExclusive, maxExclusive, totalDigits, fractionDigits.
• Example: <xsd:simpleType name=“poID”>
<xsd:restriction base=“xsd:integer”>
<xsd:minExclusive value=“100”>
<xsd:maxExclusive value=“10000”>
</xsd:restriction>
</xsd:simpleType>
![Page 21: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/21.jpg)
21
XML Schemas Complex Type
• Define complex content model, possibly have attributes and nested children.
• Example: <xsd:complexType name=“poType”>
<xsd:sequence>
<xsd:element name=“billTo” type=“addressType” />
<xsd:element name=“order”>
<xsd:sequence>
<xsd:element name=“item” type=“itemType” maxOccurs=“unbounded” />
<xsd:sequence>
</xsd:element>
</xsd:sequence>
<xsd:attribute name=“customerId” use=“required” type=“xsd:positiveInteger” />
<xsd:attribute name=“submitted” use=“required” type=“xsd:date” />
</xsd:complexType>
![Page 22: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/22.jpg)
22
Processing XML
XMLDocument
Character Stream
Serializer
Parser
StandardizedXML APIs
Application
Fig 1. Basic XML Processing Architecture
![Page 23: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/23.jpg)
23
Processing XML (2)
• Parsing models– Pull: application always ask the parser.– Push: parser sends notifications to the
application.• Simple API for XML (SAX) standard.
– One-step: parser reads the whole XML doc and generates data structure.
• Document Object Model for XML (DOM) standard.
– Hybrid: combinations of all three above.
![Page 24: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/24.jpg)
24
SAX vs DOM
• DOM provides generic object model to represent XML document plus set of interfaces to manipulate it.
• SAX fires callback events into application as it parsed the XML document element by element.
• Both are supported by Java and Microsoft development communities.
![Page 25: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/25.jpg)
25
SAX vs DOM (2)
• SAX uses less memory, more efficient for messaging.
• DOM consumes resources, but allows multiple passes through XML document (as if in-memory database or repository).
• Rule of thumb:– Need the document only to do one thing, use
SAX.– Use the document as continuing source of
data, use DOM.
![Page 26: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/26.jpg)
26
XML Transformation
• Procedure to interpret contained information in XML document.
• Transformation activities:– Put data into XML document.– Extract data from XML document.– Transform XML document from one schema
format to another.
![Page 27: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/27.jpg)
27
XML Transformation (2)
• Standard specification : Extensible Stylesheet Language Transformation (XSLT).
• XSLT is part of XSL (used to transform XML into presentation formats).
• XSLT works with DOM and SAX.
![Page 28: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/28.jpg)
28
XML Transformation (3)
• XML Path Language (XPath)– Expression language to link multiple XML
documents.– Used to define search for locating specific
element in XML document, calculation, string manipulations, and evaluating boolean expressions.
![Page 29: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/29.jpg)
29
Sample XSLT
<?xml version=“1.0” encoding=“UTF-8”>
<!-- This style sheet transform XML document into ASCII text -->
<xsl:stylesheet xmlns:”http://www.w3.org/1999/XSL/Transform” version=“1.0”>
<xsl:output method=“text” indent=“yes”>
<xsl:template match=“*”>
<xsl:apply-templates />
</xsl:template>
<xsl:template match=“company”>
Company Name:
<xsl:value-of-select=“.” />
</xsl:template>
<xsl:template match=“street”>
Street Address:
<xsl:value-of-select=“.” />
</xsl:template>
<xsl:template match=“zipcode”>
Postal Code:
<xsl:value-of-select=“.” />
</xsl:template>
![Page 30: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/30.jpg)
30
Sample XSLT (2)
• Transformation result in ASCII text format Company Name: The Soup Restaurant
Street Address: One Microsoft Way
Postal Code: 01567
![Page 31: XML and Web Services CS409 Application Services Even Semester 2007](https://reader034.vdocuments.net/reader034/viewer/2022042703/56649ec15503460f94bcc61b/html5/thumbnails/31.jpg)
31
Some XML Specifications
• XML 1.0: www.w3.org/TR/REC-xml/• XML Base: www.w3.org/TR/xmlbase/• XML Names: www.w3.org/TR/REC-xml-names/• XML Schema: www.w3.org/TR/xmlschema-1/ and
www.w3.org/TR/xmlschema-2/• XML Path: www.w3.org/TR/xpath• XML Transformation: www.w3.org/TR/xslt• DOM: www.w3.org/TR/DOM-Level-2-Core/