Introduction to XML and related technologies for use with SOAP WSDL Web services - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Introduction to XML and related technologies for use with SOAP WSDL Web services

Description:

... is also being used for application exchange formats (Open Office, XMI) CSVs ... file filename = 'funny.jpg' 14 image:description A funny picture /image: ... – PowerPoint PPT presentation

Number of Views:109
Avg rating:3.0/5.0
Slides: 31
Provided by: SW11
Category:

less

Transcript and Presenter's Notes

Title: Introduction to XML and related technologies for use with SOAP WSDL Web services


1
Presentation 6
  • Introduction to XML and related technologies
    for use with SOAP / WSDL Web services

2
Outline
  • Why an XML presentation?
  • W3C legacy of XML ultra short
  • XML markup and Namespaces
  • DTDs
  • XML Schemas
  • DOM/SAX
  • The SOAP connection

3
Why do we need an XML presentation?
  • Because SOAP, WSDL UDDI is based on XML
    technologies
  • Important to understand how the APIs work
  • Parsing mechanisms
  • DOM
  • SAX
  • Why its slow )

4
W3C the legacy of XML
  • World Wide Consortium
  • Founded 1994 to lead the WWW into the future
  • For standardizations on the Internet
  • First Chairman Tim Berners-Lee
  • Boards of members submits proposals and work to
    formulate
  • Ensures standardization of WWW technologies
  • Like XHTML, XML, XSL, CSS, SOAP, WAP etc.
  • Members Microsoft, IBM, SUN, Oracle and many
    others
  • http//www.w3c.org
  • Legacy
  • Standard Generalized Markup Language (SGML)
  • HTML has the same legacy - in fact / tightly
    coupled

5
XML markup
  • eXtended Markup Language
  • XML based on SGML (subset of)
  • Like SGML for data structure not layout (as
    HTML)
  • XML targets the Internet but is also being used
    for application exchange formats (Open Office,
    XMI) CSVs
  • XML is an W3C Recommendation
  • Structure decided by DTD or Schema (more later)
  • Wide spread support for XML

6
Presenting XML documents
  • First we will look at a standalone XML document
    and its components (elements)
  • Note XML document needs to be Well-formed
  • Please go to http//www.w3schools.com/default.asp
    to see more in-depth examples of XML usage

7
1 lt?xml version "1.0"?gt 2 3 lt!-- Fig.
20.1 article.xml --gt 4 lt!-- Article
structured with XML --gt 5 6 ltarticlegt 7
8 lttitlegtSimple XMLlt/titlegt 9 10
ltdategtSeptember 19, 2001lt/dategt 11 12
ltauthorgt 13 ltfirstNamegtTemlt/firstNamegt 14
ltlastNamegtNietolt/lastNamegt 15
lt/authorgt 16 17 ltsummarygtXML is pretty
easy.lt/summarygt 18 19 ltcontentgtOnce you
have mastered XHTML, XML is easily 20
learned. You must remember that XML is not for 21
displaying information but for managing
information. 22 lt/contentgt 23 24
lt/articlegt
Article.xml
8
Browser displaying XML (unformatted)
IE5.5 displaying article.xml.
9
Use of XML Namespaces
  • XML namespaces used to avoid naming conflicts
  • When several different elements are involved
  • ltbookgt isnt always a book
  • Keyword xmlns

10
1 lt?xml version "1.0"?gt 2 3 lt!-- Fig.
20.4 namespace.xml --gt 4 lt!-- Demonstrating
Namespaces --gt 5 6 lttextdirectory
xmlnstext "urndeiteltextInfo" 7
xmlnsimage "urndeitelimageInfo"gt 8 9
lttextfile filename "book.xml"gt 10
lttextdescriptiongtA book listlt/textdescriptiongt 1
1 lt/textfilegt 12 13 ltimagefile
filename "funny.jpg"gt 14
ltimagedescriptiongtA funny picturelt/imagedescript
iongt 15 ltimagesize width "200" height
"100"/gt 16 lt/imagefilegt 17 18
lt/textdirectorygt
Namespace.xml
11
1 lt?xml version "1.0"?gt 2 3 lt!-- Fig.
20.5 defaultnamespace.xml --gt 4 lt!-- Using
Default Namespaces --gt 5 6
ltdirectory xmlns "urndeiteltextInfo" 7
xmlnsimage "urndeitelimageInfo"gt 8 9
ltfile filename "book.xml"gt 10
ltdescriptiongtA book listlt/descriptiongt 11
lt/filegt 12 13 ltimagefile filename
"funny.jpg"gt 14 ltimagedescriptiongtA
funny picturelt/imagedescriptiongt 15
ltimagesize width "200" height "100"/gt 16
lt/imagefilegt 17 18 lt/directorygt
Defaultnamespace.xml
12
DTDs
  • Document Type Definition
  • Extended Backus-Naur Form
  • Defines how an XML document is structured
  • Required elements
  • Nesting of elements
  • Does not define types or behavior
  • If DTD is used some parsers can decide if XML
    document is valid which is more than just
    wellformed

13
1 lt!-- Fig. 20.4 letter.dtd --gt 2
lt!-- DTD document for letter.xml --gt 3 4
lt!ELEMENT letter ( contact, salutation,
paragraph, 5 closing, signature )gt 6
7 lt!ELEMENT contact ( name, address1,
address2, city, state, 8 zip, phone, flag
)gt 9 lt!ATTLIST contact type CDATA IMPLIEDgt 10
11 lt!ELEMENT name ( PCDATA )gt 12
lt!ELEMENT address1 ( PCDATA )gt 13 lt!ELEMENT
address2 ( PCDATA )gt 14 lt!ELEMENT city (
PCDATA )gt 15 lt!ELEMENT state ( PCDATA )gt 16
lt!ELEMENT zip ( PCDATA )gt 17 lt!ELEMENT phone (
PCDATA )gt 18 lt!ELEMENT flag EMPTYgt 19
lt!ATTLIST flag gender (M F) "M"gt 20 21
lt!ELEMENT salutation ( PCDATA )gt 22 lt!ELEMENT
closing ( PCDATA )gt 23 lt!ELEMENT paragraph (
PCDATA )gt 24 lt!ELEMENT signature ( PCDATA )gt
Letter.dtd
14
The ATTLIST element type declaration defines an
attribute (i.e., type) for the contact element.
1 lt!-- Fig. 20.4 letter.dtd --gt 2
lt!-- DTD document for letter.xml --gt 3 4
lt!ELEMENT letter ( contact, salutation,
paragraph, 5 closing, signature )gt 6
7 lt!ELEMENT contact ( name, address1,
address2, city, state, 8 zip, phone, flag
)gt 9 lt!ATTLIST contact type CDATA IMPLIEDgt 10
11 lt!ELEMENT name ( PCDATA )gt 12
lt!ELEMENT address1 ( PCDATA )gt 13 lt!ELEMENT
address2 ( PCDATA )gt 14 lt!ELEMENT city (
PCDATA )gt 15 lt!ELEMENT state ( PCDATA )gt 16
lt!ELEMENT zip ( PCDATA )gt 17 lt!ELEMENT phone (
PCDATA )gt 18 lt!ELEMENT flag EMPTYgt 19
lt!ATTLIST flag gender (M F) "M"gt 20 21
lt!ELEMENT salutation ( PCDATA )gt 22 lt!ELEMENT
closing ( PCDATA )gt 23 lt!ELEMENT paragraph (
PCDATA )gt 24 lt!ELEMENT signature ( PCDATA )gt
Letter.dtd
  • Assignment 5 min. make a Letter XML document
    that is
  • Well-formed (how would an XML Validator check
    this?)
  • Valid (how would an XML Validator check this?)

15
1 lt?xml version "1.0"?gt 2 3 lt!-- Fig.
20.3 letter.xml --gt 4 lt!--
Business letter formatted with XML --gt 5 6
lt!DOCTYPE letter SYSTEM "letter.dtd"gt 7 8
ltlettergt 9 10 ltcontact type "from"gt 11
ltnamegtJohn Doelt/namegt 12
ltaddress1gt123 Main St.lt/address1gt 13
ltaddress2gtlt/address2gt 14
ltcitygtAnytownlt/citygt 15
ltstategtAnystatelt/stategt 16
ltzipgt12345lt/zipgt 17 ltphonegt555-1234lt/phone
gt 18 ltflag gender "M"/gt 19
lt/contactgt 20 21 ltcontact type "to"gt 22
ltnamegtJoe Schmoelt/namegt 23
ltaddress1gtBox 12345lt/address1gt 24
ltaddress2gt15 Any Ave.lt/address2gt 25
ltcitygtOthertownlt/citygt 26
ltstategtOtherstatelt/stategt 27
ltzipgt67890lt/zipgt 28 ltphonegt555-4321lt/phone
gt 29 ltflag gender "M"/gt 30
lt/contactgt 31
Letter.xml
16
32 ltsalutationgtDear Sirlt/salutationgt 33
34 ltparagraphgtIt is our privilege to inform
you about our new 35 database managed
with XML. This new system allows 36 you
to reduce the load of your inventory list server
by 37 having the client machine perform
the work of sorting 38 and filtering the
data.lt/paragraphgt 39 ltclosinggtSincerelylt/clos
inggt 40 ltsignaturegtMr. Doelt/signaturegt 41
42 lt/lettergt
Letter.xml
17
XML Schema
  • DTD works OK but
  • Is in Ex. Backus-Naur Form why not use XML to
    describe?
  • Cannot declare the type of an element
  • ltamountgthundrede krlt/amountgt
  • Could give problems
  • Several other problems
  • W3C XML Schema
  • Use XML to describe the structure of XML
    documents
  • Possible to give type information to XML
    definitions
  • Not supported by all parsers yet
  • Will live besides DTDs for a while

18
1 lt?xml version "1.0"?gt 2 3 lt!-- Fig.
20.8 book.xsd --gt 4 lt!-- Simple
W3C XML Schema document --gt 5 6
ltxsdschema xmlnsxsd "http//www.w3.org/2000/10
/XMLSchema" 7 xmlnsdeitel
"http//www.deitel.com/booklist" 8
targetNamespace "http//www.deitel.com/booklist"
gt 9 10 ltxsdelement name "books" type
"deitelBooksType"/gt 11 12
ltxsdcomplexType name "BooksType"gt 13
ltxsdelement name "book" type
"deitelBookType" 14 minOccurs "1"
maxOccurs "unbounded"/gt 15
lt/xsdcomplexTypegt 16 17 ltxsdcomplexType
name "BookType"gt 18 ltxsdelement name
"title" type "xsdstring"/gt 19
lt/xsdcomplexTypegt 20 21 lt/xsdschemagt
Element element defines an element to be included
in the XML document structure.
Book.xsd
A BookType has an Element named Title of Type
xsdstring which is defined at
http//www.w3.org/2000/10/XMLSchema
19
(No Transcript)
20
How to use XML?
  • Need a parser (or a parser API) to access XML (as
    with CSV)
  • Two commonly used methods
  • DOM (Document Object Model)
  • W3C Recommendation
  • Makes a tree structure representation of an XML
    document in memory
  • SAX (Simple API for XML)
  • Supported by diff. vendors
  • Parses document line by line and sends events to
    subscribers
  • Needs to parse every time access to XML document
    is needed
  • DOM is better for
  • Slow to load XML document (need all)
  • Quick access to random read or update of XML
    (like WWW browser - BOM)
  • Requires a lot of memory (need to hold entire XML
    in mem)
  • SAX is better for
  • Applications subscribing to certain parts of XML
    (event subscription)
  • Slow for random access to XML document (must
    parse every time)

21
What is DOM
  • DOM Document Object Model
  • http//www.w3.org/TR/2003/REC-DOM-Level-2-HTML-200
    30109/
  • W3C definition
  • Standard for accessing structured documents
  • Core DOM used with XML
  • HTML DOM used with HTML
  • Representation of an object as an object tree
    structure
  • Provides a uniform interface for programming and
    scripting languages
  • APIs available for JavaScript, Java, C, C
    etc.

22
DOM Tree Structure
  • Tree structure of an XML document (left)
  • or HTML (right)

lttablegt lttbodygt lttrgt lttdgt
tekst lt/tdgt .
document

table

tbdoy


tr
tr
tr
td
td
td
tekst
23
Example using DOM on Article.xml
  • We have looked at Article.xml
  • We Will
  • Look at the Article.xml document again
  • Look at the Tree Structure formed by loading it
    into a DOM
  • Use JavaScript to work on it

24
1 lt?xml version "1.0"?gt 2 3 lt!-- Fig.
20.1 article.xml --gt 4 lt!-- Article
structured with XML --gt 5 6 ltarticlegt 7
8 lttitlegtSimple XMLlt/titlegt 9 10
ltdategtSeptember 19, 2001lt/dategt 11 12
ltauthorgt 13 ltfirstNamegtTemlt/firstNamegt 14
ltlastNamegtNietolt/lastNamegt 15
lt/authorgt 16 17 ltsummarygtXML is pretty
easy.lt/summarygt 18 19 ltcontentgtXML is
easily 20 learned. You must remember that
XML is not for 21 displaying information
but for managing information. 22
lt/contentgt 23 24 lt/articlegt
XML document Article.XML
25
DOM Methods
article
title
date
firstName
author
lastName
summary
contents
Tree structure for article.xml.
26
1 lt?xml version"1.0"?gt 2 lt!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 3
"http//www.w3.org/TR/xhtml1/DTD/xhtml1-tran
sitional.dtd"gt 4 lthtml xmlns"http//www.w3.org
/1999/xhtml"gt 5 6 lt!-- Fig. 20.15
DOMExample.html --gt 7 lt!-- DOM with JavaScript
--gt 8 9 ltheadgt 10
lttitlegtA DOM Examplelt/titlegt 11 lt/headgt 12
13 ltbodygt 14 15 ltscript type
"text/javascript" language "JavaScript"gt 16
lt!-- 17 var xmlDocument new
ActiveXObject( "Microsoft.XMLDOM" ) 18 19
xmlDocument.load( "article.xml" ) 20 21
// get the root element 22 var
element xmlDocument.documentElement 23
24 document.writeln( 25
"ltpgtHere is the root node of the document " 26
"ltstronggt" element.nodeName
"lt/stronggt" 27 "ltbr /gtThe following
are its child elements" 28
"lt/pgtltulgt" ) 29 30 // traverse all
child nodes of root element 31 for ( var
i 0 i lt element.childNodes.length i ) 32
var curNode element.childNodes.item(
i ) 33
DOMExample.html
27
34 // print node name of each child
element 35 document.writeln(
"ltligtltstronggt" curNode.nodeName 36
"lt/stronggtlt/ligt" ) 37 38 39
document.writeln( "lt/ulgt" ) 40 41
// get the first child node of root element 42
var currentNode element.firstChild 43
44 document.writeln( "ltpgtThe first child
of root node is " 45 "ltstronggt"
currentNode.nodeName "lt/stronggt" 46
"ltbr /gtwhose next sibling is" ) 47 48
// get the next sibling of first child 49
var nextSib currentNode.nextSibling 50 51
document.writeln( "ltstronggt"
nextSib.nodeName 52 "lt/stronggt.ltbr
/gtValue of ltstronggt" 53
nextSib.nodeName "lt/stronggt element is " ) 54
55 var value nextSib.firstChild 56
57 // print the text value of the
sibling 58 document.writeln( "ltemgt"
value.nodeValue "lt/emgt" 59 "ltbr
/gtParent node of ltstronggt" nextSib.nodeName
60 "lt/stronggt is ltstronggt" 61
nextSib.parentNode.nodeName
"lt/stronggt.lt/pgt" ) 62 --gt 63
lt/scriptgt 64 65 lt/bodygt 66 lt/htmlgt
DOMExample.html
28
Program Output
29
Tools
  • XML-Spy www.xml-spy.com
  • Suns Stylus Studio www.stylusstudio.com
  • Visual Studio 2008
  • Others
  • APIs for programmatic access
  • Java, C, C

30
The SOAP Connection
  • SOAP, WSDL, UDDI uses
  • XML
  • Namespaces
  • and Schemas
  • Original idea behind Web services
  • Connection through the Internet
  • Good sense to use XML W3C child
  • Everyone loves W3C
  • practical solutions that work
Write a Comment
User Comments (0)
About PowerShow.com