Java XML Parsing Specification - PowerPoint PPT Presentation

1 / 63
About This Presentation
Title:

Java XML Parsing Specification

Description:

XML is a subset of the earlier SGML standard. a sample XML ... Three main contenders: Microsoft .NET. IBM Web Services. Sun Open Net Environment (ONE), Java ... – PowerPoint PPT presentation

Number of Views:83
Avg rating:3.0/5.0
Slides: 64
Provided by: joo5
Category:

less

Transcript and Presenter's Notes

Title: Java XML Parsing Specification


1
Java XML Parsing Specification
2
What is XML?
  • XML is a standardised, general-purpose way of
    expressing structured data
  • XML is a subset of the earlier SGML standard

a sample XML document and a view of its structure
3
Validity and well-formedness
Validity and well-formedness are criteria for XML
documents. Validity is optional, well-formedness
is mandatory. Below are examples of how these
apply to XML documents
4
Java XML Parsing Specification
  • The Java XML Parsing Specification is a request
    to include a standardised way of parsing XML into
    the Java standard library
  • The specification defines the following packages
  • javax.xml.parsers
  • org.xml.sax
  • org.xml.sax.helpers
  • org.w3c.dom
  • The first is an all-new plugability layer, the
    others come from existing packages

5
Two ways of using XML parsers SAX and DOM
  • The Java XML Parsing Specification specifies two
    interfaces for XML parsers
  • Simple API for XML (SAX) is a flat, event-driven
    parser
  • Document Object Model (DOM) is an object-oriented
    parser which translates the XML document into a
    Java Object hierarchy

6
Creating an XML parser
XML parsers are created using the Factory design
pattern. Below are UML-like graphs of creating a
SAX parser and a DOM parser.
7
How a SAX parser works (1/2)
  • A SAX parser reads the XML document as a stream
    of XML tags starting elements, ending elements,
    text sections, etc.
  • Every time the parser encounters an XML tag it
    calls a method in its HandlerBase object to deal
    with the tag.
  • The HandlerBase object is usually written by the
    application programmer.

8
How a SAX parser works (2/2)
The HandlerBase object is given as a parameter to
the parse() method in the SAX parser. It includes
all the code that defines what the XML tags
actually do.
9
How a DOM parser works
  • A DOM parser is usually referred to as a document
    builder. It is not really a parser, more like a
    translator that uses a parser.
  • In fact, most DOM implementations include a SAX
    parser within the document builder.
  • A document builder reads in the XML document and
    outputs a hierarchy of Node objects, which
    corresponds to the structure of the XML document.

10
Output from a document builder
The parse() method of a document builder returns
a reference to the root of an object hierarchy.
The objects include references to each other as
shown below. Java is particularly well-suited for
DOM document builders since it is object-oriented
by nature.
11
Uses for XML
  • XML is useful everywhere a standard
    representation of data is needed. For example
  • Program configurations (Jakarta Tomcat)
  • Visual mark-up languages (WML, XHTML)
  • Communication protocols

12
Status of the Java XML Parsing Specification
  • The Specification is now complete. It reached
    Final stage in March 2000.
  • The Specification has not yet been implemented in
    a full release of the JDK, but it is implemented
    in the JDK 1.4 beta releases.

13
Applicaton of XMLIntroduction to Web Services
14
Introduction
  • Today, the principal use of the World Wide Web
    is for interactive access to documents and
    applications. In almost all cases, such access
    is by human users, typically working through web
    browsers
  • The Web can grow significantly in power and
    scope if it is extended to support communication
    between applications, from one program to
    another.
  • -- From the W3C XML Protocol Working Group
    Charter

15
What is a Web Service?
16
What is a Web Service?
  • A Web Service is any service that
  • Is available over the Internet or private
    (intranet) networks
  • Uses a standardized XML messaging system
  • Is not tied to any one operating system or
    programming language

17
A Basic Web Service
XML
XML
Computer B Language JavaOperating System
Linux
Computer A Language Perl Operating System
Windows 2000
18
XML Messaging
XML-RPC
  • There are several alternatives for XML messaging
  • XML Remote Procedure Calls (XML-RPC)
  • SOAP
  • Regular XML transported over HTTP
  • Any of these options are valid.

SOAP
HTTP POST/GET
XML Document
19
Web Services Defined
  • Although not required, a web service may also
    have two additional (and desirable) properties
  • a web service should be self describing.
  • a web service should be discoverable.

20
Web Services Self Describing
  • If you publish a new web service, you should also
    publish a public interface to the service.
  • At a minimum, you should include human-readable
    documentation so that others can easily integrate
    your service.
  • If you have created a SOAP service, you should
    also include a public interface written in a
    common XML grammar.

21
Web Services Discoverable
  • If you create a web service, there should be a
    relatively simple mechanism to publish this fact.
  • Likewise, interested parties should be able to
    easily discover your service.
  • The discovery service could be completely
    decentralized or completely centralized.

22
Web Services Summary
  • To summarize, a complete web service is any
    service that
  • Is available over the Internet or private
    (intranet) networks
  • Uses a standardized XML messaging system
  • Is not tied to any one operating system or
    programming language
  • Is self-describing via a common XML grammar
  • Is discoverable via a simple find mechanism

23
The Impact of Web Services
24
Web Services in Action
  • To understand the impact of web services,
    consider basic e-commerce functionality.
  • For example, Widgets Inc. sells parts through its
    web site.
  • Customers can purchase parts and check on order
    status.

25
The Web Today Human Centric
HTTP GET What is the status of my order?
Web Browser
Web Server
HTTP Response with HTML Page Leaving the
warehouse at 3 pm today.
  • This illustrates a human-centric web, where
    humans are the primary actors initiating web
    requests.
  • It also represents the primary model on which
    most of the web operates today.

26
Web Services Application-Centric Web
  • With web services, we move from a human-centric
    web to an application-centric web.
  • In other words, conversations between
    applications occur as easily as conversations
    between web browsers and servers.

27
The Application-Centric Web
XML Request What is the status of my order?
Web Server
Inventory Application
On to human users
XML Response Leaving the warehouse at 3 pm
today.
On to other applications
  • The order status is now a web service.
  • Applications can therefore connect to the order
    status service directly.

28
Application-Centric Web
  • There are numerous areas where an
    application-centric web would be extremely
    helpful
  • credit card verification
  • package tracking
  • shopping bots
  • single sign-on registration
  • calendar, email, etc.

29
Havent we seen this before?
  • An application-centric web is not a new notion.
  • For years, developers have created
  • CGI applications, Java Servlets and CORBA
    applications
  • designed primarily for use by other applications.
  • The crucial difference is that most of these
    systems consisted of ad-hoc solutions.
  • With web services, we have the promise of some
    standardization.
  • Standardization will lower the barrier to
    application integration.

30
The Long-term Vision Automated Web
  • In the long-term, web services offer the promise
    of the automated Web.
  • Just-in-time integration
  • If services are easily discoverable,
    self-describing, and stick to common standards,
    it is possible to automate application
    integration.
  • For example, consider a company, Mega Electric
    (ME) that wants to buy parts from Widgets,Inc.
  • ME wants to automatically integrate inventory
    with Widgets, Inc. order status service.

31
Just-In-Time Integration
Service Registry
1
Discover Services
Retrieve Service Description
2
Widgets Inc. Server
ME Smart Inventory Application
Service Description
Order Status Service
3
Invoke Remote Service
32
Industry Landscape
  • Many companies are investing heavily in web
    services.
  • Currently many competing frameworks for building
    web services.
  • Three main contenders
  • Microsoft .NET
  • IBM Web Services
  • Sun Open Net Environment (ONE), Java
  • All frameworks share a commitment to the same web
    services standards.

33
Standardization
  • The World Wide Web Consortium is heavily involved
    in standardizing web services.
  • SOAP is the first specification to be
    standardized.
  • http//www.w3c.org/2002/ws/
  • Web Services Interoperability Organization (WSI)
  • Industry organization
  • Designed to speed up the standardization/complianc
    e process.
  • http//www.ws-i.org/

34
Web Services Architecture
35
Web Service Architecture
  • There are two ways to view the web service
    architectural framework
  • Examine individual roles of each web service
    actor
  • Examine the emerging web service protocol stack.

36
Web Service Roles
  • Three major roles in web services
  • Service Provider provider of the web service.
  • Service Requestor any consumer of the web
    service.
  • Service Registry logically centralized
    directory of services.

37
Web Service Roles
Discover Services
Service Registry
1
Service Provider
Service Requestor
2
Invoke Service
38
Web Service Protocol Stack
  • Service transport responsible for transporting
    messages.
  • Examples HTTP, BEEP
  • XML messaging responsible for encoding messages
    in common XML format.
  • Examples XML-RPC, SOAP
  • Service Description responsible for describing
    an interface to a specific web service.
  • Example WSDL
  • Service Discovery responsible for centralizing
    services into a common search registry.
  • Example UDDI.

39
Web Service Protocol Stack
UDDI
Discovery
WSDL
Description
XML-RPC, SOAP, Custom XML
XML Messaging
HTTP, SMTP, FTP, BEEP
Transport
40
Questions?
41
Part IIWeb Service Protocols
42
XML Messaging
43
Option 1 XML-RPC
  • XML-RPC protocol that uses XML messages to
    perform Remote Procedure Calls (RPC.)
  • Platform independent diverse applications can
    talk to each other.
  • XML-RPC is the easiest way to get started with
    web services.
  • Simpler than SOAP
  • Simpler data structures for transmitting data.

44
XML-RPC Example
  • Here is a sample XML-RPC request to a weather
    service

lt?xml version"1.0" encoding"ISO-8859-1"?gt ltmetho
dCallgt ltmethodNamegtweather.getWeatherlt/methodNa
megt ltparamsgt ltparamgtltvaluegt10016lt/valuegtlt
/paramgt lt/paramsgt lt/methodCallgt
Give me the current weather conditions in zip
code 10016.
45
XML-RPC Example
  • Here is a sample Weather response

lt?xml version"1.0" encoding"ISO-8859-1"?gt ltmetho
dResponsegt ltparamsgt ltparamgt
ltvaluegtltintgt65lt/intgtlt/valuegt lt/paramgt
lt/paramsgt lt/methodResponsegt
Current temperature is 65 degrees
46
Option 2 SOAP
  • SOAP used to stand for Simple Object Access
    Protocol
  • XML-Based protocol for exchanging information
    between computers.
  • Currently a formal recommendation of the World
    Wide Web Consortium (W3C.)

47
SOAP Message Format
SOAP Message
Envelope (Required)
Header (Optional)
Body (Required)
Fault (Optional Response only)
48
SOAP 1.1 Example
  • Here is a sample SOAP request to a weather
    service

lt?xml version'1.0' encoding'UTF-8'?gt ltSOAP-ENVE
nvelope xmlnsSOAP-ENV"http//www.w3.org/2001/
09/soap-envelope/" xmlnsxsi"http//www.w3.org
/2001/XMLSchema-instance" xmlnsxsd"http//www
.w3.org/2001/XMLSchema"gt ltSOAP-ENVBodygt
ltns1getWeather xmlnsns1"urnexamples
weatherservice" SOAP-ENVencodingStyle"h
ttp//www.w3.org/2001/09/soap-encoding/"gt
ltzipcode xsitype"xsdstring"gt10016lt/zipcodegt
lt/ns1getWeathergt lt/SOAP-ENVBodygt lt/SOAP-E
NVEnvelopegt
49
SOAP 1.1 Example
  • Here is a sample SOAP response

lt?xml version'1.0' encoding'UTF-8'?gt ltSOAP-ENVE
nvelope xmlnsSOAP-ENV"http//www.w3.org/2001/
09/soap-envelope/" xmlnsxsi"http//www.w3.org
/2001/XMLSchema-instance" xmlnsxsd"http//www
.w3.org/2001/XMLSchema"gt ltSOAP-ENVBodygt
ltns1getWeatherResponse
xmlnsns1"urnexamplesweatherservice"
SOAP-ENVencodingStyle"http//www.w3.org/2001/09/
soap-encoding/"gt ltreturn
xsitype"xsdint"gt65lt/returngt
lt/ns1getWeatherResponsegt lt/SOAP-ENVBodygt lt/SO
AP-ENVEnvelopegt
50
WSDL UDDI
51
WSDL
  • WSDL Web Service Description Language.
  • WSDL is an XML grammar for specifying an
    interface for a web service.
  • Specifies
  • location of web service
  • methods that are available by the web service
  • data type information for all XML messages
  • WSDL is commonly used to describe SOAP services.

52
WSDL In a Nutshell
ltdefinitionsgt Root WSDL Element
lttypesgt What data types will be transmitted?
ltmessagegt What messages will be transmitted?
ltportTypegt What operations (functions) will be
supported?
ltbindinggt What SOAP specific details are there?
ltservicegt Where is the service located?
53
WSDL Excerpt Weather Service
ltmessage name"getWeatherRequest"gt ltpart
name"zipcode" type"xsdstring"/gt lt/messagegt
ltmessage name"getWeatherResponse"gt ltpart
name"temperature" type"xsdint"/gt
lt/messagegt ltportType name"Weather_PortType"gt
ltoperation name"getWeather"gt
ltinput message"tnsgetWeatherRequest"/gt
ltoutput message"tnsgetWeatherResponse"/gt
lt/operationgt lt/portTypegt
54
WSDL Excerpt Weather Service
ltservice name"Weather_Service"gt
ltdocumentationgtWSDL File for Weather
Servicelt/documentationgt ltport
binding"tnsWeather_Binding" name"Weather_Port
"gt ltsoapaddress
location"http//ecerami.com/soap/servlet/rpcroute
r"/gt lt/portgt lt/servicegt lt/definitionsgt
55
So What?
  • Given a WSDL file, a developer can immediately
    figure out how to connect to the web service.
  • Eases overall integration process.
  • Better yet, with WSDL tools, you can automate the
    integration

56
WSDL Invocation Tools
  • For example, IBM has a tool called Web Services
    Invocation Framework (WSIF).
  • Given a WSDL file, the tool will automatically
    invoke the service.
  • A number of other tools from Microsoft, GLUE, and
    open source projects also do this.

57
WSIF Example
  • Invoke WSIF with the Weather WSDL File specify
    method name and zip code parameter
  • java clients.DynamicInvoker http//localhost8080/
    wsdl/WeatherService.wsdl getWeather 10016
  • generates the following output
  • Reading WSDL document from 'http//localhost8080/
    wsdl/WeatherService.wsdl'
  • Preparing WSIF dynamic invocation
  • Executing operation getWeather
  • Result
  • temperature65
  • Done!

58
UDDI
  • UDDI Universal Description, Discovery and
    Integration.
  • Currently represents the discovery layer in the
    protocol stack.
  • Originally created by Microsoft, IBM and Ariba.
  • Technical specification for publishing and
    finding businesses and web services.

59
UDDI Two Parts
  • Part I Technical specification
  • specification for building a distributed
    directory of businesses and services.
  • XML format for specifying businesses and
    services.
  • API for querying/publishing to the registry.
  • Part II Implementation
  • UDDI Business Registry, fully operational
    implementation of the specification.
  • Businesses can publish services here.
  • Businesses can discover services here.
  • Currently maintained by IBM, Microsoft, etc.

60
UDDI Data
  • White Pages
  • Information about a specific company name
    description, address, etc.
  • Yellow Pages
  • Classification data for company or service.
  • For example industry, product or geographic
    codes.
  • Green Pages
  • Technical information about specific services.
  • Pointers to WSDL Files.

61
All Together Now!
62
Using the Protocols Together
Find Services via UDDI
Step 1
Retrieve Service Description File WSDL or
XML-RPC Instructions
Step 2
Create XML-RPC or SOAP Client
Step 3
Invoke Remote Service
Step 4
63
Questions?
Write a Comment
User Comments (0)
About PowerShow.com