JAX- Java APIs for XML by J. Pearce. Some XML Standards Basic –SAX (sequential access parser) –DOM (random access parser) –XSL (XSLT, XPATH) –DTD Schema.

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Web architectures – Laurea Specialistica in Informatica – Università di Trento Java XML parsing.
Advertisements

The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc.
The Semantic Web. The Web Today Designed for Human to read Cannot express meaning Architecture: URL –Decentralized: Link structure Language: html.
SDPL 2002Notes 3: XML Processor Interfaces1 3.3 JAXP: Java API for XML Processing n How can applications use XML processors? –A Java-based answer: through.
SDPL 2003Notes 3: XML Processor Interfaces1 3.3 JAXP: Java API for XML Processing n How can applications use XML processors? –A Java-based answer: through.
XML Parsers By Chongbing Liu. XML Parsers  What is a XML parser?  DOM and SAX parser API  Xerces-J parsers overview  Work with XML parsers (example)
SAX A parser for XML Documents. XML Parsers What is an XML parser? –Software that reads and parses XML –Passes data to the invoking application –The application.
14-Jun-15 DOM. SAX and DOM SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C standard SAX is an ad-hoc.
Tomcat Java and XML. Announcements  Final homework assigned Wednesday  Two week deadline  Will cover servlets + JAXP.
©Silberschatz, Korth and Sudarshan10.1Database System Concepts W3C Activities HTML: is the lingua franca for publishing on the Web XHTML: an XML application.
Parsing XML into programming languages JAXP, DOM, SAX, JDOM/DOM4J, Xerces, Xalan, JAXB.
Xerces The Apache XML Project Yvonne Yao. Introduction Set of libraries that provides functionalities to parse XML documents Set of libraries that provides.
21-Jun-15 SAX (Abbreviated). 2 XML Parsers SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C standard.
1 Processing XML with Java CS , Spring 2008/9.
MC365 XML Parsers. Today We Will Cover: An overview of the Java API’s used for XML processing Creating an XML document in Java Parsing an XML document.
XML: Java Dr Andy Evans. Java and XML Couple of things we might want to do: Parse/write data as XML. Load and save objects as XML. We’ll mainly discuss.
SDPL : (XML APIs) JAXP1 3.3 JAXP: Java API for XML Processing n How can applications use XML processors? –In Java: through JAXP –An overview of.
Processing of structured documents Spring 2003, Part 5 Helena Ahonen-Myka.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
17 Apr 2002 XML Programming: JAXP Andy Clark. Java API for XML Processing Standard Java API for loading, creating, accessing, and transforming XML documents.
The Joy of SAX (and DOM, and JDOM…) Bill MacCartney 11 October 2004.
1 XML at a neighborhood university near you Innovation 2005 September 16, 2005 Kwok-Bun Yue University of Houston-Clear Lake.
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
Structured-Document Processing Languages Spring 2011 Course Review Repetitio mater studiorum est!
Java API for XML Processing (JAXP) توسط : محمّدمهدي حامد استاد راهنما : دكتر مسعود رهگذر.
SDPL 2004Notes 3: XML Processor Interfaces1 3.3 JAXP: Java API for XML Processing n How can applications use XML processors? –A Java-based answer: through.
Advanced Java Session 9 New York University School of Continuing and Professional Studies.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
1 JAXP & XSLT. Objectives 2  TrAX API  Transforming XML Documents  Workshops.
3/29/2001 O'Reilly Java Java API for XML Processing 1.1 What’s New Edwin Goei Engineer, Sun Microsystems.
1 Java and XML Modified from presentation by: Barry Burd Drew University Portions © 2002 Hungry Minds, Inc.
EXtensible Markup Language (XML) James Atlas July 15, 2008.
SAX. What is SAX SAX 1.0 was released on May 11, SAX is a common, event-based API for parsing XML documents Primarily a Java API but there implementations.
XML Processing in Java. Required tools Sun JDK 1.4, e.g.: JAXP (part of Java Web Services Developer Pack, already in Sun.
Java API for XML Processing (JAXP) Dr. Rebhi S. Baraka Advanced Topics in Information Technology (SICT 4310) Department of Computer.
Sheet 1XML Technology in E-Commerce 2001Lecture 3 XML Technology in E-Commerce Lecture 3 DOM and SAX.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
Document Object Model DOM. Agenda l Introduction to DOM l Java API for XML Parsing (JAXP) l Installation and setup l Steps for DOM parsing l Example –Representing.
Java and XML. What is XML XML stands for eXtensible Markup Language. A markup language is used to provide information about a document. Tags are added.
© Marty Hall, Larry Brown Web core programming 1 Simple API for XML SAX.
SAX2 and DOM2 Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML and SAX (A quick overview) ● What is XML? ● What are SAX and DOM? ● Using SAX.
Schema Data Processing
1 JAXP & XPATH. Objectives 2  XPath  JAXP Processing of XPath  Workshops.
Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
Structured-Document Processing Languages Spring 2004 Course Review Repetitio mater studiorum est!
Web services. DOM parsing and SOAP.. Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first.
©Silberschatz, Korth and Sudarshan10.1Database System Concepts W3C - The World Wide Web Consortium W3C - The World Wide Web Consortium.
Martin Kruliš by Martin Kruliš (v1.1)1.
7-Mar-16 Simple API XML.  SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files  DOM is a W3C standard  SAX is an.
13-Mar-16 DOM. 2 Difference between SAX and DOM DOM reads the entire XML document into memory and stores it as a tree data structure SAX reads the XML.
USING ANDROID WITH THE DOM. Slide 2 Lecture Summary DOM concepts SAX vs DOM parsers Parsing HTTP results The Android DOM implementation.
21-Jun-16 Document Object Model DOM. SAX and DOM SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C.
Java API for XML Processing
XML. Contents  Parsing an XML Document  Validating XML Documents.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Parsing XML into programming languages
Java/XML.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XML in Web Technologies
XML Parsers By Chongbing Liu.
Java API for XML Processing
DOM 8-Dec-18.
WaysInJavaToParseXML
A parser for XML Documents
DOM 24-Feb-19.
XML document processing in Java using XPath and XSLT
Presentation transcript:

JAX- Java APIs for XML by J. Pearce

Some XML Standards Basic –SAX (sequential access parser) –DOM (random access parser) –XSL (XSLT, XPATH) –DTD Schema Linking & Presentation –XPATH, XLINK, XBASE, XHTML Semantic Web –RDF (Resource Description Framework) –OWL (Ontology Web Language) –XTP (XML Topic Maps)

JAX Supports Java Web Services Java Web Service is a B2B service implemented in Java Web clients, apps, and services communicate and share data using XML JAX is a layer of APIs that sits on top of J2EE

JAX Consists of Document-oriented –JAXP (JAX Processing) Procedure-oriented –JAX-RPC (SOAP method calls) –JAX-M (SOAP messages) –JAX-R (business registries)

Major JAX packages javax.xml.soap javax.xml.transform javax.xml.rpc javax.xml.messaging javax.xml.namespace javax.xml.parsers org.w3c.dom org.xml.sax

JAXP Includes: javax.xml.parsers –SAX API –DOM API javax.xml.transform –XSLT API javax.xml.namespace

Parsers SAX is an event-notification parser DOM is a tree-building parser

SAX

Parsing Using SAX DefaultHandler handler = new MyHandler(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); saxParser.parse( new File("tree.xml"), handler );

A SAX Event Handler class MyHandler extends DefaultHandler { public void startElement(...) { // start processing detected element } public void endElement(...) { // finish processing detected element } public void characters(...) { // process text element } // etc. }

Creating a DOM Document

DOM Interfaces

makeDocument(String xmlFile) // obtain parser factory: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //obtain parser: DocumentBuilder builder = factory.newDocumentBuilder(); // parse an xml document into a DOM tree: Document doc = builder.parse(new File(xmlFile));

The Visitor Design Pattern Problem: We want to process each node in a tree, but there are many types of nodes. Solution: Put the node processing methods in a separate object called a visitor. When a visitor visits a node of type T, the correct method is automatically invoked. Visitors can use depth- or bredth-first traversal

A DOM Visitor

Visiting a Document public class Visitor { protected String name, value; protected int depthCounter = 0; public void visit(Document doc) { try { visit((Node)doc.getDocumentElement()); } catch(VisitorException e) { handle(e); } public void visit(Node node) throws VisitorException {... } public void visit(NodeList nodes) throws VisitorException {... } // overridables: protected void visit(Element node) throws VisitorException { } protected void visit(Text node) throws VisitorException { } protected void visit(Attr node) throws VisitorException { } protected void handle(VisitorException e) { System.err.println("visitor exception: " + e); } }

Visiting a Node public void visit(Node node) throws VisitorException { name = node.getNodeName(); value = node.getNodeValue(); switch (node.getNodeType()) { case Node.ELEMENT_NODE:... case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE:... // etc. } // switch } // visit node

Visiting an Element Node: case Node.ELEMENT_NODE: Element elem = (Element) node; depthCounter++; visit(elem); NamedNodeMap attributeNodes = node.getAttributes(); for(int i = 0; i < attributeNodes.getLength(); i++) { Attr attribute = (Attr) attributeNodes.item(i); depthCounter++; visit(attribute); depthCounter--; } depthCounter--; visit(node.getChildNodes()); break;

Visiting Text Nodes case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: Text text = (Text) node; depthCounter++; visit(text); depthCounter--; break;

Visiting Child Nodes public void visit(NodeList nodes) throws VisitorException { for(int i = 0; i < nodes.getLength(); i++) { depthCounter++; visit(nodes.item(i)); depthCounter--; } }

XSLT in JAX

MakeXMLFile() static public void makeXMLFile(String xmlFile, Document doc) { try { Source xmlSource = new DOMSource(doc); Result result = new StreamResult( new FileOutputStream(xmlFile)); TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); transformer.setOutputProperty("indent", "yes"); transformer.transform(xmlSource, result); } catch(Exception e) { } }