19
The Java™ Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc.

The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Embed Size (px)

Citation preview

Page 1: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

The Java™ Platform and XML

Portable Code, Portable Data

James Duncan DavidsonStaff Engineer, Sun Microsystems, Inc.

Page 2: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Our Overall Goals

• Adopt existing open standards allowing the use of XML by Java™ developers

• Participate in the various XML groups such as W3C and OASIS

• Integrate XML technologies into the Core Platform as appropriate

Page 3: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Our Activities

• W3C Participation• XML Working Group• DOM Working Group• XSL Working Group

• Developing APIs• JAXP• Data Bindings

• Experimenting / Implementing• Project X

Page 4: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Java API for XML Parsers (JAXP)• A thin and lightweight API for

parsing XML documents

• Allows for pluggable parsers

• Allows processing of XML documents using the predominant methods:– Callback Driving (SAX)– Tree Based (DOM)

Page 5: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

JAXP Illustration

JAXP

ReferenceParser

OtherParser

User Application

Java Runtime

Page 6: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

SAX 1.0

• Simple API for XML

• Accesses Document Serially

• Fast and Lightweight

• Harder to Program

• Sequential Access Only

• API in packages org.xml.sax.*

Page 7: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

SAX in Action

SaxParser

UserProvidedHandler

XMLInput

EventsCalled

Page 8: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Using SAX via JAXP

import java.xml.parsers.*;import org.xml.sax.*;

String uri = “http://server/resource.xml”;SAXParserFactory spf;SAXParser parser;HandlerBase handler;

spf = SAXParserFactory.newInstance();spf.setValidating(true);parser = spf.newSAXParser();parser.parse(uri, handler);

// can also parse InputStreams, Files, and SAX// input sources

Page 9: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

DOM Level 1

• Document Object Model

• Access XML Documents via a tree structure

• Composed of element nodes and text nodes

• Can “walk” the tree back and forth

• Larger memory requirements

• Package: org.w3c.dom.*

Page 10: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

DOM in Action

DocumentBuilder

XMLInput

CreatesTree

Page 11: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Using DOM with JAXP

import java.xml.parsers.*;import org.w3c.dom.*;

String uri = “http://server/resource.xml”;DocumentBuilderFactory dbf;DocumentBuilder builder;Document document;

dbf = DocumentBuilderFactory.newInstance();dbf.setValidating(true);builder = dbf.newDocmentBuilder();document = builder.parse(uri);

// can also parse InputStreams, Files, and SAX// input sources

Page 12: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Namespaces

• Defines a distinct set of XML markup elements

• Associates a URI with a prefix

• Allows multiple vocabularies to be combined in a single XML document

Page 13: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Namespace Example

<?xml version=“1.0”?><book xmlns=“http://server/book” xmlns:isbn=“http://other.gov/isbn”> <title>Cheaper by the Dozen</title> <isbn:number>1568491379</isbn:number></book>

Page 14: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Namespaces in JAXP

// SAX Casespf = SAXParserFactory.newInstance();spf.setValidating(true);spf.setNamespaceAware(true);parser = spf.newSAXParser();parser.parse(uri, handler);

// DOM Casedbf = DocumentBuilderFactory.newInstance();dbf.setValidating(true);dbf.setNamespaceAware(true);builder = dbf.newDocmentBuilder();document = builder.parse(uri);

Page 15: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Using a Compliant Parser• Factories are looked up using

System properties• javax.xml.parsers.SAXParserFactory

• javax.xml.parsers.DocumentBuilderFactory

• Change the property and you can use any parser

Page 16: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

JAXP Schedule

• Spec 1.0 Final Release– Available REAL SOON NOW

• Reference Implementation– Final Version REAL SOON NOW

• 1.1– Starting now– Preliminary specs by Summer time

Page 17: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

XML Futures

• Participate in spec evolution– XSL/XSLT– Schemas– Xlink / Xpointer– XQL

• Code– JAXP under consideration for Core– Work with Apache– Work with OASIS

Page 18: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

Summary

• XML, What it is:– Portable Data

• XML and the Java™ Platform– Portable Code + Portable Data

• JAXP Overview

• Roadmap

Page 19: The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc

</presentation><?q&a?>

http://java.sun.com/[email protected]

http://www.xml.orghttp://xml.apache.orghttp://www.xml.com

[email protected]@[email protected]