1
XML and Web Services
Lecture 8
2
Outline
- XML (Section 17)
– XML syntax, semistructured data – Document Type Definitions (DTDs) – XML Schema
- Introduction to XML based Web Services
XML and Web Services Lecture 8 1 Outline XML (Section 17) XML - - PDF document
XML and Web Services Lecture 8 1 Outline XML (Section 17) XML syntax, semistructured data Document Type Definitions (DTDs) XML Schema Introduction to XML based Web Services 2 Additional Readings on XML XML
1
2
– XML syntax, semistructured data – Document Type Definitions (DTDs) – XML Schema
3
– http://www.w3.org/XML/1999/XML-in-10-points – www.zvon.org/xxl/XMLTutorial/General/book_en.html – http://www.w3.org/TR/REC-xml-names (1/99)
4
– Standardized General Markup Language
5
– I cant “give” you my relational database – Need to import it from other syntax, like CSV (comma-separated-values)
– But XML is not relational: semi-structured
– Map any data to XML – Store it in files, exchange on the Web, Web services etc. – Even query it directly, using XPath, XQuery
6
application relational data
Transform Integrate Warehouse
XML Data WEB (HTTP)
application application legacy data
Specific data management tasks
7
8
9
<bibliography> <book> <title> Foundations… </title> <author> Abiteboul </author> <author> Hull </author> <author> Vianu </author> <publisher> Addison Wesley </publisher> <year> 1995 </year> </book> … </bibliography>
10
well formed XML document
11
12
<?xml version='1.0' encoding='utf-8'?> <!-- A full XML Example --> <book price = “55” currency = “EUR”> <title> Foundations of Databases </title> <author> Abiteboul </author> … <year> 1995 </year> </book>
13
– Same syntax as in HTML
– Good documentation should be provided using comments
14
<data> <person id=“o555” > <name> Mary </name> <address> <street> Maple </street> <no> 345 </no> <city> Seattle </city> </address> </person> <person> <name> John </name> <address> Thailand </address> <phone> 23456 </phone> </person> </data>
data Mary person person name address name address street no city Maple 345 Seattle John Thai phone 23456 id
Element node Text node Attribute node
Order matters !!!
15
<person id=“o555”> <name> Jane </name> </person> <person id=“o456”> <name> Mary </name> <children idref=“o123 o555”/> </person> <person id=“o123” mother=“o456”><name>John</name> </person>
16
<persons> <row> <name>John</name> <phone> 3634</phone></row> <row> <name>Sue</name> <phone> 6343</phone> <row> <name>Dick</name> <phone> 6363</phone></row> </persons>
row row row name name name phone phone phone “John” 3634 “Sue” “Dick” 6343 6363
persons XML:
persons
6363 Dick 6343 Sue 3634 John Phone Name
17
– Relational schema: persons(name,phone) – In XML <persons>, <name>, <phone> are part of the data, and are repeated many times
– However, XML data is redundant!
18
– Organised in semantic chunks (entities) – Are grouped together, have same format
– Data can be of any type
– Entities may not have the same attributes – Not all attributes may be required – Order of attributes not necessarily important – Nested and heterogeneous
19
a table with nulls
<person> <name> John</name> <phone>1234</phone> </person> <person> <name>Joe</name> </person> no phone !
1234 John phone name
20
<person> <name> Mary</name> <phone>2345</phone> <phone>3456</phone> </person> two phones ! 3456 2345 Mary phone name
???
21
– <db> contains both <book>s and <publisher>s <person> <name> <first> John </first> <last> Smith </last> </name> <phone>1234</phone> </person>
structured name !
22
– Document Type Description (DTD)
– XML Schema
23
well-formed = if tags are correctly closed valid = if it has a DTD and conforms to it
24
<!DOCTYPE company [ <!ELEMENT company ((person|product)*)> <!ELEMENT person (ssn, name, office, phone?)> <!ELEMENT ssn (#PCDATA)> <!ELEMENT name (#PCDATA)> <!ELEMENT office (#PCDATA)> <!ELEMENT phone (#PCDATA)> <!ELEMENT product (pid, name, description?)> <!ELEMENT pid (#PCDATA)> <!ELEMENT description (#PCDATA)> ]>
25
<company> <person> <ssn> 123456789 </ssn> <name> John </name> <office> B432 </office> <phone> 1234 </phone> </person> <person> <ssn> 987654321 </ssn> <name> Jim </name> <office> B123 </office> </person> <product> ... </product> ... </company>
Example of valid XML document:
26
– Complex = a regular expression over other elements – Text-only = #PCDATA – Empty = EMPTY – Any = ANY – Mixed content = (#PCDATA | A | B | C)* – * … 0 or many – + … at least one – ? … 0 or 1
<!ELEMENT tag (CONTENT)>
content model
27
<!ELEMENT name (firstName, lastName))
<name> <firstName> . . . . . </firstName> <lastName> . . . . . </lastName> </name>
<!ELEMENT name (firstName?, lastName))
DTD XML
<!ELEMENT person (name, phone*))
sequence
<!ELEMENT person (name, (phone|email)))
star (repeated occurrence) alternation
<person> <name> . . . . . </name> <phone> . . . . . </phone> <phone> . . . . . </phone> <phone> . . . . . </phone> . . . . . . </person> <name> <lastName> . . . . . </lastName> </name> <person> <name> . . . . . </name> <email> . . . . . </email> </person> 28
<!ELEMENT person (ssn, name, office, phone?)> <!ATTLIST person age CDATA #REQUIRED "18" birthdate CDATA #IMPLIED nationality CDATA #FIXED "CH" gender (male|female) "female">
<person age="24" nationality="CH" gender="male"> <ssn> … </ssn> …<phone> … </phone> </person>
mandatory
default enumeration
29
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE test PUBLIC "-//Test AG//DTD test V1.0//EN" SYSTEM "http://www.test.org/test.dtd"> <test> "test" is a document element </test> <!DOCTYPE test SYSTEM "http://www.test.org/test.dtd" [ <!ENTITY hello "hello world"> ]> <test>&hello;</test> <!DOCTYPE test [ <!ELEMENT test EMPTY> ]> <test/>
External DTD Declaration Internal DTD Declaration Mixed usage
30
– Only allows for very simple data types
– Uses same syntax as XML documents – Allows for basic (built-in) and complex data types
31
Would like to have an entity called Person …
32
<complexType name=“Person”> <sequence> <element name=“Name” type=“string”> <element name=“age” type=“integer”> <element name=“Address” type=“string” minOccurs=“1” maxOccurs=“unbounded”> </sequence> </complexType> <Person> <Name>Antonia</Name> <age>23</age> <Address>1015 Lausanne</Address> <Address>1010 Vienna</Address> </Person>
33
– how to avoid conflicts when combining names from different DTDs/XMLSchemas?
– identified by a prefix (URL reference)
34
<book xmlns='urn:loc.gov:book' xmlns:isbn='www.isbn-org.org/def'> <title> … </title> <number> 15 </number> <isbn:number> …. </isbn:number> </book> default name space names belong to default name space
35
<tag xmlns:mystyle = “http://…”> … <mystyle:title> … </mystyle:title> <mystyle:number> … </tag>
– URL may not exist, has no function
Belong to this namespace
36 <?xml version="1.0" encoding="ISO-8859-1" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="shiporder"> <xs:complexType> <xs:sequence> <xs:element name="orderperson" type="xs:string"/> <xs:element name="shipto"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="address" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="country" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="item" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string"/> <xs:element name="note" type="xs:string" minOccurs="0"/> <xs:element name="quantity" type="xs:positiveInteger"/> <xs:element name="price" type="xs:decimal"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="orderid" type="xs:string" use="required"/> </xs:complexType> </xs:element> </xs:schema>
37
– XML syntax, semistructured data – Document Type Definitions (DTDs) – XML Schema
38
application programs, built using standard Internet technologies.
is implemented. Application client Application program Network Web Service
39
– Typically an HTTP server that serves Web pages such as the EPFL Web site
– Provides a programmable interface to client applications
– We can write Java, C++, …, applications to access the service
40
performs functions (or a function).
self-contained, self-describing, modular applications that can be published, located, and invoked across the Web. Web services perform functions, which can be anything from simple requests to complicated business processes. … Once a Web service is deployed, other applications (and other Web services) can discover and invoke the deployed service.” IBM web service tutorial
41
– HTTP, “home-grown”, SOAP, etc. – Messages need to be exchanged between client and server – Communication should be “fast” – Independent of programming language,
42
InfoPoint Service client San Francisco, time 0:30 PST San Francisco, temp 11 C
43
String getTime(String city) String getTemp(String city) int getAltitude(String city)
44
– Listen on a certain port – Speak a certain protocol
– Open a socket connection and use TCP/IP – Send a few bytes
– Wait for a response
– What is the problem with “home-grown” protocols on top of TCP/IP?
45
responses
GET /index.html HTTP/1.1 Host: server.example.org HTTP/1.1 200 OK Connection: close Content-Length: 80 Content-Type: text/html Date: Wed, 25 Feb 2007 14:07:42 GMT <HTML> <BODY> <H1>Introduction to Info Sys</H1> The course provides … </BODY> </HTML>
Request Response
46
– Which method to call? – Which parameters (data types)?
POST /InfoPoint HTTP/1.1 Host: server.example.org getTime(“San Francisco”) … HTTP/1.1 200 OK Connection: close Content-Length: 80 Content-Type: text/html Date: Wed, 25 Feb 2007 14:07:42 GMT Time=0:30
Request Response
47
48
String getTime(String city) String getTemp(String city) int getAltitude(String city)
<InfoPoint> <getTimeRequest> <city>San Francisco</city> </getTimeRequest> </InfoPoint> <InfoPoint> <getTimeResponse> <time>0:30 PST</time> </getTimeResponse> </InfoPoint>
Request Response
49
POST /InfoPoint HTTP/1.1 Host: server.example.org <InfoPoint> <getTimeRequest> <city>San Francisco</city> </getTimeRequest> </InfoPoint> HTTP/1.1 200 OK Connection: close Content-Type: text/xml Date: Wed, 25 Feb 2007 14:07:42 GMT <InfoPoint> <getTimeResponse> <time>0:30 PST</time> </getTimeResponse> </InfoPoint>
Request Response
50
Service provider Service broker Service requestor
publish (WSDL) find (UDDI) bind (SOAP) "server" "client" "naming service"
51
– Not bound to any programming language nor
– Client only needs to understand
requests/responses: SOAP
– Will be discussed next time
52
– Often, lots of redundancy in messages – Can lead to performance issues
53
– Axis for Java
Web Server HTTP SOAP client
54
– Relational tables can easily be exported into XML
– Use XML to exchange messages