JAXB Java Architecture for XML Bindings. What is JAXB? JAXB defines the behavior of a standard set of tools and interfaces that automatically generate.

Slides:



Advertisements
Similar presentations
ANT: Another Nice Tool Ali Beyad October 1, 2003.
Advertisements

ANT: Another Nice Tool Ali Beyad October 1, 2003.
JAXB Java Architecture for XML Binding Andy Fanton Khalid AlBayat.
Lab#1 (14/3/1431h) Introduction To java programming cs425
XML Parsing Using Java APIs AIP Independence project Fall 2010.
1 Ant – Another Neat Tool Representation and Management of Data on the Internet.
Java API for XML Processing (JAXP) CSE 4/586: Distributed Systems Department of Computer Science and Engineering University at Buffalo, New York Jia Zhao.
Winter 2005Jason Prideaux1 Apache ANT A platform independent build tool for Java programs.
Fonts and colors Times New Roman “quotes” Trebuchet "quotes" yellow blue pink green violet.
Cspp51037 Parsing XML into other programming languages – alternatives to XSLT.
29-Jun-15 JAXB Java Architecture for XML Binding.
XML Schema Presenters: Tong, Lei. Outline XML Schema Overview XML Schema Components XML Schema Reusability & Conformance XML Schema Applications and IDE.
Unit 4 – XML Schema XML - Level I Basic.
Technical Track Session XML Techie Tools Tim Bornholt.
Chapter 13 XML Concept of XML Simple Example of XML XML vs. HTML in Syntax XML Structure DTD and CDATA Sections Concept of SAX Processing Download and.
Web Services with Apache CXF Part 2: JAXB and WSDL to Java Robert Thornton.
By: Shawn Li. OUTLINE XML Definition HTML vs. XML Advantage of XML Facts Utilization SAX Definition DOM Definition History Comparison between SAX and.
17 Apr 2002 XML Schema Andy Clark. What is it? A grammar definition language – Like DTDs but better Uses XML syntax – Defined by W3C Primary features.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
1 Lecture 22 George Koutsogiannakis Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
ESO - Garching 23 June – 02 July, 2003 ACS Course Data entities and XML serialization H. Sommer.
XML Schema Vinod Kumar Kayartaya. What is XML Schema?  XML Schema is an XML based alternative to DTD  An XML schema describes the structure of an XML.
School of Computing and Management Sciences © Sheffield Hallam University To understand the Oracle XML notes you need to have an understanding of all these.
XML eXtensible Markup Language w3c standard Why? Store and transport data Easy data exchange Create more languages WSDL (Web Service Description Language)
XML What is XML? XML v.s. HTML XML Components Well-formed and Valid Document Type Definition (DTD) Extensible Style Language (XSL) SAX and DOM.
SAX Parsing Presented by Clifford Lemoine CSC 436 Compiler Design.
Sheet 1XML Technology in E-Commerce 2001Lecture 7 XML Technology in E-Commerce Lecture 7 XSL Formatting Objects, Java Data Binding.
XML – Tools and Trends Schematron Tim Bornholtz Session 55.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
XML Parsers Overview  Types of parsers  Using XML parsers  SAX  DOM  DOM versus SAX  Products  Conclusion.
Working with the XML Document Object Model ©NIITeXtensible Markup Language/Lesson 7/Slide 1 of 44 Objectives In this lesson, you will learn to: *Identify.
Copyright © Curt Hill Java Looking at our first console application in Eclipse.
Intro to XML Originally Presented by Clifford Lemoine Modified by Box.
SDPL 2005Notes 2.5: XML Schemas1 2.5 XML Schemas n Short introduction to XML Schema –W3C Recommendation, 1 st Ed. May, 2001; 2 nd Ed. Oct, 2004: »XML Schema.
Web Services with Apache CXF Part 2: JAXB and WSDL to Java Robert Thornton.
Sheet 1XML Technology in E-Commerce 2001Lecture 3 XML Technology in E-Commerce Lecture 3 DOM and SAX.
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
XML Grammar and Parser for WSOL Kruti Patel, Vladimir Tosic, Bernard Pagurek Network Management & Artificial Intelligence Lab Department of Systems & Computer.
Web Services with Apache CXF Part 2: JAXB and WSDL to Java Robert Thornton.
XML Study-Session: Part III
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.
CS 157B: Database Management Systems II February 18 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
When we create.rtf document apart from saving the actual info the tool saves additional info like start of a paragraph, bold, size of the font.. Etc. This.
What is XML? eXtensible Markup Language eXtensible Markup Language A subset of SGML (Standard Generalized Markup Language) A subset of SGML (Standard Generalized.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
Web services. DOM parsing and SOAP.. Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first.
Accessing XML Documents Using DOM ©NIITeXtensible Markup Language/Lesson 8/Slide 1 of 23 Objectives In this lesson, you will learn to: * Use XML DOM objects.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
CHAPTER NINE Accessing Data Using XML. McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Introduction The eXtensible.
Generating ADL Descriptions ADL Module for Together 6.x Massimo Marino Lawrence Berkeley National Laboratory.
Java High level programming language ◦ Sun Microsystems ◦ ORACLE acquired Java Development Kit – JDK Java Runtime Environment – JRE Java Virtual Machine.
4 Copyright © 2004, Oracle. All rights reserved. Validating XML by Using XML Schema.
Solvency II Tripartite template V2 and V3 Presentation of the conversion tools proposed by FundsXML France.
I Copyright © 2004, Oracle. All rights reserved. Introduction.
Chapter 13 XML Concept of XML Simple Example of XML
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Unit 4 Representing Web Data: XML
Web Services-JAX-RPC JAX-RPC enables a Web Service endpoint to be developed using either a Java Servlet or Enterprise JavaBeans (EJB) component model.
Intro to XML.
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
XML Problems and Solutions
XML Parsers.
XML and Web Services (II/2546)
New Perspectives on XML
Presentation transcript:

JAXB Java Architecture for XML Bindings

What is JAXB? JAXB defines the behavior of a standard set of tools and interfaces that automatically generate java class files from XML schema JAXB is a framework or architecture, not an implementation. Sun provides a reference implementation of JAXB with the Web Services Developers kit, available as a separate download

JAXB vs. DOM and SAX JAXB is a higher level construct than DOM or SAX –DOM represents XML documents as generic trees –SAX represents XML documents as generic event streams –JAXB represents XML documents as Java classes with properties that are specific to the particular XML document E.g. book.xml becomes Book.java with getTitle, setTitle, etc. JAXB thus requires almost no knowledge of XML to be able to programmatically process XML documents!

High-level comparison Before diving into details of JAXB, it’s good to see a bird’s-eye-view of the difference between JAXB and SAX and/or DOM-like parsers Study the books/ examples under the examples/jaxb directory on the course website

JAXB steps We start by assuming that you have a valid installation of java web services developers pack version 3. We cover these installation details later Using JAXB then requires several steps: 1.Run the binding compiler on the schema file to automagically produce the appropriate java class files 2.Compile the java class files (ant tool helps here) 3.Study the autogenerated api to learn what java types have been created 4.Create a program that unmarshals an xml document into these elementary data structures

Running binding compiler /jaxb/bin/xjc.sh -p test.jaxb books.xsd -d work –xjc.sh : executes binding compiler –-p test.jaxb : place resulting class files in package test.jaxb –books.xsd : run compiler on schema books.xsd –-d work : place resulting files in directory called work/ Note that this creates a huge number of files that together represent the content of the books.xsd schema as a set of Java classes It is not necessary to know all of these classes. We’ll study them only at a high level so we can understand how to use them

Example: students.xsd

Generated interfaces xjc.sh -p test.lottery students.xsd This generates the following interfaces –test/lottery/ObjectFactory.java Contains methods for generating instances of the interfaces –test/lottery/Students.java Represents the root node –test/lottery/StudentsType.java Represents the unnamed type of each student object

Generated implementations Each interface is implemented in the impl directory –test/lottery/impl/StudentsImpl.java Vendor-specific implementation of the Students inteface –test/lottery/impl/StudentsTypeImpl.java Vendor-specific implementation of the StudentsType Interface

Compilation Next, the generated classes must be compiled: –javac students/*.java students/impl/*.java CLASSPATH requires many jar files: –jaxb/lib/*.jar –jwsdp-shared/lib/*.jar –jaxp/lib/**/*.jar Note: an ant buildfile (like a java makefile) makes this much easier. More on this later

Generated docs Java API docs for these classes are generated in –students/docs/api/*.html After bindings are generated, one usually works directly through these API docs to learn how to access/manipulate the XML data.

Sample Programs

Easiest way to learn is to cover certain generic sample cases. These are all on the course website under cspp53025/examples/jaxb Summary of examples: –student/ Use JAXB to read an xml document composed of a single student complex type –student/ Same, but for an xml document composed of a sequence of such student types of indefinite length –purchaseOrder/ Another read example, but for a more complex schema

Sample programs, cont Course examples, cont –create-marshal Purchase-order example modified to create in memory and write to XML –modify-marshal Purchase-order example modified to read XML, change it and write back to XML Study these examples!

Some additional JAXB details

Binding Data Types Default java datatype bindings can be found at: These defaults can be changed if required for an application Also, name binding are fairly standard changes of names to things acceptable in java programming language See other binding rules on subsequent pages

Default binding rules summary The JAXB binding model follows the default binding rules summarized below: Bind the following to Java package: –XML Namespace URI Bind the following XML Schema components to Java content interface: –Named complex type –Anonymous inlined type definition of an element declaration Bind to typesafe enum class: –A named simple type definition with a basetype that derives from "xsd:NCName" and has enumeration facets. Bind the following XML Schema components to a Java Element interface: –A global element declaration to a Element interface. –Local element declaration that can be inserted into a general content list. Bind to Java property: –Attribute use –Particle with a term that is an element reference or local element declaration. Bind model group with a repeating occurrence and complex type definitions with mixed {content type} to: –A general content property; a List content-property that holds Java instances representing element information items and character data items.