190 likes | 321 Vues
This document outlines the integration of XML technologies within the Java™ platform, focusing on the Java API for XML Parsers (JAXP). It highlights the goals of adopting open standards, participating in XML development groups, and enhancing the core platform with XML technologies. Key topics include SAX and DOM parsing methods, namespaces, and factory usage for compliant XML parsing. This educational guide serves as an overview of XML in Java, detailing API development and future XML initiatives, ultimately empowering developers to leverage XML effectively in their applications.
E N D
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
Our Activities • W3C Participation • XML Working Group • DOM Working Group • XSL Working Group • Developing APIs • JAXP • Data Bindings • Experimenting / Implementing • Project X
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)
JAXP Illustration User Application JAXP Reference Other Parser Parser Java Runtime
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.*
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
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.*
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
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
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>
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);
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
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
XML Futures • Participate in spec evolution • XSL/XSLT • Schemas • Xlink / Xpointer • XQL • Code • JAXP under consideration for Core • Work with Apache • Work with OASIS
Summary • XML, What it is: • Portable Data • XML and the Java™ Platform • Portable Code + Portable Data • JAXP Overview • Roadmap
</presentation><?q&a?> http://java.sun.com/xml james.davidson@sun.com http://www.xml.org http://xml.apache.org http://www.xml.com xml-announce@java.sun.com xml-interest@java.sun.com xml-feedback@java.sun.com