Java And Xml

  • Uploaded by: Uday Kumar
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Java And Xml as PDF for free.

More details

  • Words: 1,765
  • Pages: 13
© 2001 First Hop

Java and XML Janne Kalliola Director, Product Development First Hop Ltd

Java and XML ƒ ƒ

ƒ

ƒ

ƒ

About XML Basic XML manipulation ƒ DOM ƒ SAX Transforming and outputting XML documents ƒ XSLT ƒ XSL-FO New generation technologies ƒ Java XML Bindings ƒ Java XML Messaging ƒ JAX-RPC Case – configuration information

1

About XML ƒ

ƒ

ƒ

Extensible Markup Language (XML) is a W3C recommendation for representing information in electronical form XML is a meta language; it does not provide any semantics, only the basic syntax and conformance tests ƒ everything else can be decided by the provider of the XML document There are dozens of initiatives to create various languages over XML ƒ MathML ƒ XHTML ƒ SOAP

Using XML ƒ

ƒ

ƒ

In the beginning XML was strictly thought as a textual document ƒ the representation of the document structure was a file containing elements and body text Nowadays XML is used programmatically, thus documents can also be ƒ data structures ƒ events ƒ streams In this presentation, the word "document" is used to cover all of these aspects

2

XML as Objects ƒ

ƒ

XML documents can be manipulated in object oriented software using Document Object Model (DOM) interfaces ƒ DOM is a W3C (www.w3.org) recommendation ƒ programming language and implementation independent ƒ interfaces available for several languages including Java, C++, Python, and IDL ƒ DOM is also used in browsers to manipulate HTML content The basic idea in DOM is to read XML documents into trees and manipulate the tree

DOM Levels and Implementations ƒ

ƒ

DOM contains currently three levels: 1. basic manipulation interfaces 2. event based XML document manipulation, tree travelsal and style sheets (CSS) 3. XML Schemas, Xpath There are several implementations available, such as JAXP from Sun Microsystems, and Xerces from Apache Foundation ƒ the implementations are usually called XML parsers ƒ contains implementations for the DOM interfaces and supporting code ƒ the support of different levels varies from implementation to another

3

Event-based Manipulation ƒ

ƒ

If the XML documents are large or only a part of the document should be read in, DOM can consume too much memory and resources ƒ the solution is to read the XML document as a serie of events ƒ every XML element triggers an event ƒ the program reading in the document catches the events and reacts accordingly ƒ the document is read element by element and thus no large data structures are created The event-based manipulation is done with SAX (Simple API for XML) ƒ the SAX implementations are usually bundled with DOM implementations

Transforming XML ƒ

ƒ

If the source XML document is outside the system using the document, the source document may be in a format that is not optimal or usable for the system The document has to be transformed into another XML syntax ƒ the transformation is hard to program with normal programming languages ƒ instead, a special programming language Extensible Style Language Transformations (XSLT) has been created for solving this problem

4

XSLT ƒ

ƒ

XSLT is rule-based language ƒ the XSLT syntax is based on XML, i.e. XSLT programs (stylesheets) are XML documents ƒ the XSLT contains rules to transform elements, attributes and subdocuments to another form The XSLT stylesheet is run inside a XSLT processor ƒ the processor gets the source document and the stylesheet as input and produces another XML documents as output ƒ the processor reads in part of the source document and tries to find matching rules ƒ if a rule is found, it is executed and the rule produces a part of the output document ƒ there are default rules for ruleless situations ƒ the process goes on recursively until the source document has been completely processed

XSL Formatting Objects ƒ

ƒ

XSL-FO is an XML-based language to describe layout information ƒ the XSL-FO document contains instructions to render itself, like DTP program documents ƒ the document is rendered using an XSL-FO processor ƒ the processor outputs a document in some format such as PDF or PostScript XSL-FO is a young recommendation, finalised on October 2001 ƒ programmatic support is still in beta level

5

Outputting Human-readable Documents ƒ

If the XML document has to be presented to a person, there are two basic ways to proceed: ƒ convert the document to XHTML and show the output document with a WWW browser ƒ transformation is done using XSLT and the output is readily available for presentation ƒ convert the document to XSL-FO and format the document to some desired output format ƒ transformation is done using XSLT and the output is rendered to the final output format by XSL-FO processor

Transformations in Java ƒ

ƒ

Both XSLT and XSL-FO can be used inside Java programs ƒ XSLT interfaces are included in JAXP ƒ XSLT processors are available for example from IBM, Sun Microsystems and Apache Foundation XSL-FO is currently still in beta phase ƒ the best Java-based processor is FOP, provided by Apache Foundation, xml.apache.org/fop ƒ FOP provides output as PDF, PS, PCL, SVG ƒ FOP can also be used to render the documents inside a Java program, using the supplied AWT component

6

New Generation Technologies ƒ

ƒ

The first uses of XML in Java were very documentoriented ƒ reading in and writing out documents ƒ using XML in WWW applications for content presentation, or as a configuration file format ƒ transforming documents to other forms New APIs are geared towards using XML in a programmatic manner ƒ the programmers are shielded from the bare XML documents ƒ APIs are provided instead and XML formats are kept on the background

Java XML Bindings ƒ

ƒ

If XML documents contain only computer readable information, DOM and SAX are cumbersome technologies to read the documents in ƒ semantics has to be provided by the software itself Sun Microsystems has proposed a solution for the problem ƒ Java XML Bindings (JAXB) is an API and collection of tools to automate mappings between XML documents and Java classes ƒ JAXB is currently in development, for more information: http://java.sun.com/xml/jaxb/

7

JAXB Mechanisms ƒ

ƒ ƒ

JAXB provides a compiler that creates Java classes from XML DTDs (document type definition) ƒ XML Schema support will be available shortly ƒ DTD is converted to a Binding Schema that is used to create the classes Generated classes contain error and validity checks as stated in DTDs Classes can both read in and generate XML documents

JAXB Benefits & Problems ƒ

ƒ

ƒ

ƒ

Easier programming model ƒ some parts of program logic are written with a description language Smaller footprint for XML parsing ƒ no need to keep redundant information in the memory during parsing Program logic is divided into two locations ƒ there are some versioning problems, when the DTDs change Automatisation may generate poor code

8

Java XML Messaging ƒ

ƒ ƒ

ƒ

Java XML Messaging (JAXM) is a set of APIs that enable sending and receiving XML formatted messages ƒ implements Simple Object Access Protocol (SOAP) 1.1 with attachments JAXM is used to exchange XML business documents over the Internet Transportation is usually done over HTTP ƒ FTP and SMTP can be used, too ƒ messages can be both synchronous and asynchronous (with or without acknowledgements) ƒ one message can be sent to several recipients For more information: http://java.sun.com/xml/jaxm/

JAXM Benefits ƒ

ƒ

Help the developers to concentrate on the core features of the program ƒ messaging details are left to JAXM components ƒ provides several transports to interchange messages Messages can be exchanged with non-Java applications, too

9

JAX-RPC ƒ

ƒ

ƒ

Java API for XML-Based Remote Procedure Calls enables Java applications to communicate with other programs using RPC mechanism ƒ the API is based on SOAP 1.1 Usually, JAX-RPC is used in a client program to connect to a remote server ƒ client initiates a remote procedure call in the server ƒ server has defined a set of calls that are available for the clients (remote API of the server) JAX-RPC is thus similar to RMI (remote method invocation) or CORBA (common object request broker architecture)

JAX-RPC Functionality ƒ ƒ

ƒ

The remote procedure call is represented using an XML based protocol (for instance SOAP 1.1) The server can define, describe and export a web service as an RPC based service ƒ the service is described using Web Service Description Language (WDSL) ƒ XML based specification to describe service as a set of endpoints that operate on messages ƒ WDSL is a World Wide Web Consortium (W3C) specification For more information: http://java.sun.com/xml/jaxrpc/

10

Java XML Packs ƒ

ƒ

Sun Microsystems has collected all the available APIs to a Java XML Pack ƒ the pack contains a set of interoperable Java XML technologies ƒ Sun Microsystems releases a new version of the pack quarterly ƒ http://java.sun.com/xml/javaxmlpack.html Packs should not be confused with JAXP (Java API for XML Processing) ƒ contains DOM and SAX parsers and XSLT processor ƒ JAXP forms the base of Java XML Pack

Case – Description ƒ

First Hop products' configuration information is stored in an XML file ƒ the file is read in by the main controller of the product ƒ the configurations are grouped by the components of the product ƒ eases maintaining of the configuration ƒ the contents of the file are dissected to several parts and given to the appropriate components ƒ every component gets only its own configuration ƒ configurations can be embedded, if a component uses another component internally

11

Case – Benefits ƒ ƒ

ƒ

The configuration is kept in a single file ƒ reduces number of files to be manipulated The configuration is flexible ƒ the syntax of the component configuration is specified by the component ƒ the configurations can be nested, if required The configuration is automatically checked ƒ if the syntax of the configuration is wrong, DOM raises errors ƒ no need to create own configuration parsers

Summary ƒ

ƒ

There are two levels of XML manipulation ƒ the first one is based on the document aspects of XML ƒ older standards, more implementations ƒ generic solutions ƒ the second one is based on programmatic use of XML ƒ new standards, usually one or few implementations ƒ some are still in a draft phase ƒ specific solutions Java and XML provide a wide range of possibilities for application programmers

12

Questions & Comments? ƒ ƒ

ƒ

For more information about First Hop: www.firsthop.com For information about XML: ƒ http://java.sun.com/xml/ ƒ http://www.w3.org/ ƒ http://www.xml.com/ You can reach me at [email protected]

13

Related Documents

Java And Xml
November 2019 24
Java And Xml
November 2019 14
Java Html Xml
November 2019 45
Xml Programming In Java
December 2019 13
Using Xml In Java
December 2019 24

More Documents from "Ashraf Bashir"

Web Services Slides
November 2019 13
Wsdlcontracts
November 2019 13
Jax-ws
November 2019 13
Wsdl11soap12
November 2019 17
Hibernate Join Fetch
October 2019 19