1 / 32

XML and Web Services

XML and Web Services. CS409 Application Services. Even Semester 2007. 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. Document-Centric XML.

schuyler
Télécharger la présentation

XML and Web Services

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML and Web Services CS409 Application Services Even Semester 2007

  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.

  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.

  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>

  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.

  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>

  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.

  8. XML Instances • Anatomy of instance: • Declaration • Comments • Elements • Attributes • CDATA section

  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>

  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.

  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>

  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> ]]>

  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.

  14. XML Without Namespaces <message from=“buyer@store.com” to=“seller@doddystore.com” 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>

  15. XML With Namespaces <message from=“buyer@store.com” to=“seller@mystore.com” 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>

  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.

  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>

  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>

  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.

  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>

  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>

  22. Processing XML Application XML Document Character Stream Standardized XML APIs Serializer Parser Fig 1. Basic XML Processing Architecture

  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.

  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.

  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.

  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.

  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.

  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.

  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>

  30. Sample XSLT (2) • Transformation result in ASCII text format Company Name: The Soup Restaurant Street Address: One Microsoft Way Postal Code: 01567

  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/

  32. Thank You Doddy Lukito dlukito@infinitechnology.com dlukito@alumni.carnegiemellon.edu

More Related