html5-img
1 / 63

Java XML Parsing Specification

Java XML Parsing Specification. 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. Validity and well-formedness.

azura
Télécharger la présentation

Java XML Parsing Specification

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. 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?” • 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. Web Browser Web Server HTTP Response with HTML Page: “Leaving the warehouse at 3 pm 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?” • The order status is now a web service. • Applications can therefore connect to the order status service directly. Web Server Inventory Application On to human users XML Response: “Leaving the warehouse at 3 pm today.” On to other applications

  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. Haven’t 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/compliance 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 Discovery UDDI Description WSDL XML Messaging XML-RPC, SOAP, Custom XML Transport HTTP, SMTP, FTP, BEEP

  40. Questions?

  41. Part II:Web 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: <?xml version="1.0" encoding="ISO-8859-1"?> <methodCall> <methodName>weather.getWeather</methodName> <params> <param><value>10016</value></param> </params> </methodCall> “Give me the current weather conditions in zip code: 10016.”

  45. XML-RPC Example • Here is a sample Weather response: <?xml version="1.0" encoding="ISO-8859-1"?> <methodResponse> <params> <param> <value><int>65</int></value> </param> </params> </methodResponse> “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: <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/09/soap-envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <ns1:getWeather xmlns:ns1="urn:examples:weatherservice" SOAP-ENV:encodingStyle="http://www.w3.org/2001/09/soap-encoding/"> <zipcode xsi:type="xsd:string">10016</zipcode> </ns1:getWeather> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

  49. SOAP 1.1 Example: • Here is a sample SOAP response: <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/09/soap-envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <ns1:getWeatherResponse xmlns:ns1="urn:examples:weatherservice" SOAP-ENV:encodingStyle="http://www.w3.org/2001/09/soap-encoding/"> <return xsi:type="xsd:int">65</return> </ns1:getWeatherResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

  50. WSDL & UDDI

More Related