SlideShare a Scribd company logo
XML and Java Alex Chaffee, alex@jguru.com http://www.purpletech.com
Overview Why Java and XML? Parsers: DOM, JDOM, SAX Using XML from JSP Java/XML Object Mapping Resources
Why Java/XML? XML maps well to Java late binding hierarchical (OO) data model Unicode support in Java XML Structures map well to Java Objects Portability Network friendly
XML Parsers Validating/Non-Validating Tree-based Event-based SAX-compliance Not technically parsers XSL XPath
Some Java XML Parsers DOM Sun JAXP IBM XML4J Apache Xerces Resin (Caucho) DXP (DataChannel) SAX Sun JAXP SAXON JDOM
Dom API Tree-based Node classes Part of W3C spec Sorting/Modifying of Elements Sharing document with other applications
XML is a Tree <?xml version=&quot;1.0&quot;?> <!DOCTYPE menu SYSTEM &quot;menu.dtd&quot;> <menu> <meal name=&quot;breakfast&quot;> <food>Scrambled Eggs</food> <food>Hash Browns</food> <drink>Orange Juice</drink> </meal> <meal name=&quot;snack&quot;> <food>Chips</food> </meal> </menu> menu meal name &quot;breakfast&quot; food &quot;Scrambled Eggs&quot; food &quot;Hash Browns&quot; drink &quot;Orange Juice&quot; meal
DOM API (cont’d) Based on Interfaces Good design style - separate interface from implementation Document, Text, Processing Instruction, Element - ALL are interfaces All extend interface Node Including interface Attr (parentNode is null, etc)
DOM Example public void print(Node node) {  //recursive method call using DOM API... int type = node.getNodeType(); case Node.ELEMENT_NODE: // print element with attributes out.print('<'); out.print(node.getNodeName()); Attr attrs[] = node.getAttributes(); for (int i = 0; i < attrs.length; i++) { Attr attr = attrs[i]; out.print(' ');  out.print(attr.getNodeName());out.print(&quot;=\&quot;&quot;); out.print(normalize(attr.getNodeValue()));  out.print('&quot;'); } out.print('>'); NodeList children = node.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) { print(children.item(i)); } } break; case Node.ENTITY_REFERENCE_NODE: // handle entity reference nodes // ...
DOM API Highlights Node getNodeType() getNodeName() getNodeValue() returns null for Elements getAttributes() returns null for non-Elements getChildNodes() getParentNode() Element getTagName() same as getNodeName() getElementsByTagName(String tag) get all children of this name, recursively normalize() smooshes text nodes together Attr attributes are not technically child nodes getParent() et al. return null getName(), getValue() Document has one child node  - the root element call getDocumentElement() contains factory methods for creating attributes, comments, etc.
DOM Level 2 Adds namespace support, extra methods Not supported by Java XML processors yet
The Trouble With DOM Written by C programmers Cumbersome API Node does double-duty as collection Multiple ways to traverse, with different interfaces Tedious to walk around tree to do simple tasks Doesn't support Java standards (java.util collections)
JDOM: Better than DOM Java from the ground up Open source Clean, simple API Uses Java Collections
JDOM vs. DOM Classes / Interfaces Java / Many languages Java Collections / Idiosyncratic collections getChildText() and other useful methods / getNextSibling() and other useless methods
JDOM: The Best of Both Worlds Clean, easy to use API document.getRootElement().getChild(&quot;book&quot;). getChildText(&quot;title&quot;) Random-access tree model (like DOM) Can use SAX for backing parser Open Source, not Standards Committee Allowed benevolent dictatorship -> clean design
JDOM Example XMLOutputter out = new XMLOutputter(); out.output( element, System.out ); Or…  public void print(Element node) {  //recursive method call using JDOM API... out.print('<'); out.print(node.getName()); List attrs = node.getAttributes();  for (int i = 0; i < attrs.size(); i++) { Attribute attr = (Attribute)attrs.get(i); out.print(' ');  out.print(attr.getName());out.print(&quot;=\&quot;&quot;); out.print(attr.getValue() );  out.print('&quot;'); } out.print('>'); List children = node.getChildren(); if (children != null) { for (int i = 0; i < children.size(); i++) { print(children.item(i)); } }
JDOM Example public Element toElement(User dobj) throws IOException { User obj = (User)dobj; Element element = new Element(&quot;user&quot;); element.addAttribute(&quot;userid&quot;, &quot;&quot;+user.getUserid()); String val; val = obj.getUsername(); if (val != null) {   element.addChild(new Element(&quot;username&quot;).setText(val)); } val = obj.getPasswordEncrypted(); if (val != null) {   element.addChild(new  Element(&quot;passwordEncrypted&quot;).setText(val)); } return element; }
JDOM Example public User fromElement(Element element) throws DataObjectException { List list; User obj = new User(); String value = null; Attribute userid = element.getAttribute(&quot;userid&quot;); if (userid != null) {   obj.setUserid( userid.getIntValue() ); } value = element.getChildText(&quot;username&quot;); if (value != null) {   obj.setUsername( value ); } value = element.getChildText(&quot;passwordEncrypted&quot;); if (value != null) {   obj.setPasswordEncrypted( value ); } return obj; }
DOMUtils DOM is clunky DOMUtils.java - set of utilities on top of DOM http://www.purpletech.com/code Or just use JDOM
Event-Based Parsers Scans document top to bottom Invokes callback methods Treats XML not like a tree, but like a list (of tags and content) Pro: Not necessary to cache entire document Faster, smaller, simpler Con:  must maintain state on your own can't easily backtrack or skip around
SAX API Grew out of xmldev mailing list (grassroots) Event-based startElement(), endElement() Application intercepts events Not necessary to cache entire document
Sax API (cont’d) public void startElement(String name, AttributeList atts) { // perform implementation out.print(“Element name is “ + name); out.print(“, first attribute is “ + atts.getName(0) + “, value is “ + atts.getValue(0)); }
XPath The stuff inside the quotes in XSL Directory-path metaphor for navigating XML document &quot;/curriculum/class[4]/student[first()]&quot; Implementations  Resin (Caucho) built on DOM JDOM has one in the &quot;contrib&quot; package Very efficient API for extracting specific info from an XML tree Don't have to walk the DOM or wait for the SAX Con: yet another syntax / language, without full access to Java libraries
XSL eXtensible Stylesheet Language transforms one XML document into another XSL file is a list of rules Java XSL processors exist Apache Xalan (not to be confused with Apache Xerces) IBM LotusXSL Resin SAXON XT
Trouble with XSL It's a programming language masquerading as a markup language Difficult to debug Turns traditional programming mindset on its head Declarative vs. procedural Recursive, like Prolog Doesn't really separate presentation from code
JSP JavaServer Pages Outputting XML <%  User = loadUser(request.getParameter(&quot;username&quot;)); response.setContentType(&quot;text/xml&quot;); %> <user> <username><%=user.getUsername()%></username> <realname><%=user.getRealname()%></realname> </user> Can also output HTML based on XML parser, naturally (see my &quot;JSP and XML&quot; talk, or http://www.purpletech.com)
XMLC A radical solution to the problem of how to separate presentation template from logic… …to actually separate the presentation template from the logic!
XMLC Architecture HTML (with ID tags) Java Class (e.g. Servlet) HTML Object (automatically generated) XMLC HTML (dynamically-generated) Setting values Data Reading data
XMLC Details Open-source (xmlc.enhydra.org) Uses W3C DOM APIs Generates &quot;set&quot; methods per tag Source: <H1 id=&quot;title&quot;>Hello</H1> Code: obj.setElementTitle(&quot;Goodbye&quot;)  Output: <H1>Goodbye</H1> Allows graphic designers and database programmers to develop in parallel Works with XML source too
XML and Java in 2001 Many apps' config files are in XML Ant Tomcat Servlets Several XML-based Sun APIs JAXP JAXM ebXML SOAP (half-heartedly supported   )
Java XML Documentation Jdox Javadoc -> single XML file http://www.componentregistry.com/ Ready for transformation (e.g. XSL) Java Doclet http://www.sun.com/xml/developers/doclet Javadoc -> multiple XML files (one per class) Cocoon Has alpha XML doclet
Soapbox: DTDs are irrelevant DTDs describe structure of an unknown document But in most applications, you already know the structure – it's implicit in the code If the document does not conform, there will be a runtime error, and/or corrupt/null data This is as it should be! GIGO. You could have a separate &quot;sanity check&quot; phase, but parsing with validation &quot;on&quot; just slows down your app Useful for large-scale document-processing applications, but not for custom apps or transformations
XML and Server-Side Java
Server-Side Java-XML Architecture Many possible architectures XML Data Source disk or database or other data feed Java API DOM or SAX or XPath or XSL XSL optional transformation into final HTML, or HTML snippets, or intermediate XML Java Business Logic  JavaBeans and/or EJB Java Presentation Code Servlets and/or JSP and/or XMLC
Server-Side Java-XML Architecture Java UI Java Business Logic XML Processors XML Data Sources HTML JSP JavaBeans Servlet EJB DOM, SAX XPath XSL Filesystem XML-savvy RDBMS XML Data Feed
Server-Side Architecture Notes Note that you can skip any layer, and/or call within layers e.g. XML->XSL->DOM->JSP, or JSP->Servlet->DOM->XML
Cache as Cache Can Caching is essential Whatever its advantages, XML is  slow Cache results on disk and/or in memory
XML <-> Java Object Mapping
XML and Object Mapping Java -> XML Start with Java class definitions Serialize them - write them to an XML stream Deserialize them - read values in from previously serialized file XML -> Java Start with XML document type Generate Java classes that correspond to elements Classes can read in data, and write in compatible format (shareable)
Java -> XML Implementations Java -> XML BeanML Coins / BML Sun's XMLOutputStream/XMLInputStream XwingML (Bluestone) JDOM BeanMapper Quick? JSP (must roll your own)
BeanML Code (Extract) <?xml version=&quot;1.0&quot;?> <bean class=&quot;java.awt.Panel&quot;> <property name=&quot;background&quot; value=&quot;0xeeeeee&quot;/> <property name=&quot;layout&quot;> <bean class=&quot;java.awt.BorderLayout&quot;/> </property> <add> <bean class=&quot;demos.juggler.Juggler&quot; id=&quot;Juggler&quot;> <property name=&quot;animationRate&quot; value=&quot;50&quot;/> <call-method name=&quot;start&quot;/> </bean> <string>Center</string> </add> … </bean>
Coins Part of MDSAX Connect XML Elements and JavaBeans Uses Sax Parser, Docuverse DOM to convert XML into JavaBean Uses BML - (Bindings Markup Language) to define mapping of XML elements to Java Classes
JDOM BeanMapper Written by Alex Chaffee   Default implementation outputs element-only XML, one element per property, named after property Also goes other direction (XML->Java) Doesn't (yet) automatically build bean classes Can set mapping to other custom element names / attributes
XMLOutputStream/XMLInputStream From some Sun engineers http://java.sun.com/products/jfc/tsc/articles/persistence/ May possibly become core, but unclear Serializes Java classes to and from XML Works with existing Java Serialization Not tied to a specific XML representation You can build your own plug-in parser Theoretically, can be used for XML->Java as well
XMLOutputStream/XMLInputStream
 
XML -> Java Implementations XML -> Java Java-XML Data Binding (JSR 31 / Adelard) IBM XML Master (Xmas) Purple Technology XDB Breeze XML Studio (v2)
Adelard (Java-XML Data Binding) Java Standards Request 31 Still vapor! (?)
Castor Implementation of JSR 31 http://castor.exolab.org Open-source
IBM XML Master (&quot;XMas&quot;) Not vaporware - it works!!! Same idea as Java-XML Data Binding From IBM Alphaworks Two parts builder application visual XML editor beans
Brett McLaughlin's Data Binding Package See JavaWorld articles
Purple Technology XDB In progress (still vapor) Currently rewriting to use JDOM JDOMBean helps Three parts XML utility classes XML->Java data binding system Caching filesystem-based XML database (with searching)
Conclusion Java and XML are two great tastes that taste great together
Resources XML Developments: Elliot Rusty Harold:  Café Con Leche - metalab.unc.edu/xml Author, XML Bible Simon St. Laurent www.simonstl.com Author, Building XML Applications General www.xmlinfo.com www.oasis-open.org/cover/xml.html www.xml.com www.jdm.com www.purpletech.com/xml
Resources: Java-XML Object Mapping JSR 31 http://java.sun.com/aboutJava/communityprocess/jsr/jsr_031_xmld.html http://java.sun.com/xml/docs/binding/DataBinding.html XMas http://alphaworks.ibm.com/tech/xmas
Resources XSL: James Tauber:  xsl tutorial: www.xmlsoftware.com/articles/xsl-by-example.html Michael Kay Saxon home.iclweb.com/icl2/mhkay/Saxon.html James Clark  XP Parser, XT editor, XSL Transformations W3C Spec
Resources: JDOM www.jdom.org
Thanks To John McGann Daniel Zen David Orchard My Mom
Ad

More Related Content

What's hot (20)

XML
XMLXML
XML
Mukesh Tekwani
 
XML and DTD
XML and DTDXML and DTD
XML and DTD
Jussi Pohjolainen
 
Xml dtd
Xml dtdXml dtd
Xml dtd
sana mateen
 
Xml 215-presentation
Xml 215-presentationXml 215-presentation
Xml 215-presentation
Manish Chaurasia
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
Pradeep Rapolu
 
Dtd
DtdDtd
Dtd
Abhishek Kesharwani
 
Document Type Definitions
Document Type DefinitionsDocument Type Definitions
Document Type Definitions
Randy Riness @ South Puget Sound Community College
 
XML
XMLXML
XML
Mukesh Tekwani
 
Xml dtd
Xml dtdXml dtd
Xml dtd
HeenaRajput1
 
DTD
DTDDTD
DTD
Kamal Acharya
 
XML's validation - DTD
XML's validation - DTDXML's validation - DTD
XML's validation - DTD
videde_group
 
4 xml namespaces and xml schema
4   xml namespaces and xml schema4   xml namespaces and xml schema
4 xml namespaces and xml schema
gauravashq
 
Dtd
DtdDtd
Dtd
Manish Chaurasia
 
2 dtd - validating xml documents
2   dtd - validating xml documents2   dtd - validating xml documents
2 dtd - validating xml documents
gauravashq
 
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XMLFergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
dri_ireland
 
XML
XMLXML
XML
Daminda Herath
 
01 Xml Begin
01 Xml Begin01 Xml Begin
01 Xml Begin
Dennis Pipper
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
Bình Trọng Án
 
Document type definition
Document type definitionDocument type definition
Document type definition
Raghu nath
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
BG Java EE Course
 

Viewers also liked (20)

Oracle xmldb
Oracle xmldbOracle xmldb
Oracle xmldb
Hermes Romero
 
Xml
XmlXml
Xml
Pilar Fernández Belloso
 
Grupo1
Grupo1Grupo1
Grupo1
Jose Lara
 
Java and XML
Java and XMLJava and XML
Java and XML
Raji Ghawi
 
JAXP
JAXPJAXP
JAXP
Pon Akilan Senthilvel
 
Java Web Service - Summer 2004
Java Web Service - Summer 2004Java Web Service - Summer 2004
Java Web Service - Summer 2004
Danny Teng
 
Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108
nit Allahabad
 
Simple API for XML
Simple API for XMLSimple API for XML
Simple API for XML
guest2556de
 
Java Web Services [2/5]: Introduction to SOAP
Java Web Services [2/5]: Introduction to SOAPJava Web Services [2/5]: Introduction to SOAP
Java Web Services [2/5]: Introduction to SOAP
IMC Institute
 
Java Web Services [5/5]: REST and JAX-RS
Java Web Services [5/5]: REST and JAX-RSJava Web Services [5/5]: REST and JAX-RS
Java Web Services [5/5]: REST and JAX-RS
IMC Institute
 
Java Web Services [3/5]: WSDL, WADL and UDDI
Java Web Services [3/5]: WSDL, WADL and UDDIJava Web Services [3/5]: WSDL, WADL and UDDI
Java Web Services [3/5]: WSDL, WADL and UDDI
IMC Institute
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
Surinder Kaur
 
Java Web Services [1/5]: Introduction to Web Services
Java Web Services [1/5]: Introduction to Web ServicesJava Web Services [1/5]: Introduction to Web Services
Java Web Services [1/5]: Introduction to Web Services
IMC Institute
 
Web Technologies in Java EE 7
Web Technologies in Java EE 7Web Technologies in Java EE 7
Web Technologies in Java EE 7
Lukáš Fryč
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
Jussi Pohjolainen
 
Java Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web ServicesJava Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web Services
IMC Institute
 
6 xml parsing
6   xml parsing6   xml parsing
6 xml parsing
gauravashq
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
srinivasanjayakumar
 
Community and Java EE @ DevConf.CZ
Community and Java EE @ DevConf.CZCommunity and Java EE @ DevConf.CZ
Community and Java EE @ DevConf.CZ
Markus Eisele
 
Writing simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorWriting simple web services in java using eclipse editor
Writing simple web services in java using eclipse editor
Santosh Kumar Kar
 
Java Web Service - Summer 2004
Java Web Service - Summer 2004Java Web Service - Summer 2004
Java Web Service - Summer 2004
Danny Teng
 
Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108
nit Allahabad
 
Simple API for XML
Simple API for XMLSimple API for XML
Simple API for XML
guest2556de
 
Java Web Services [2/5]: Introduction to SOAP
Java Web Services [2/5]: Introduction to SOAPJava Web Services [2/5]: Introduction to SOAP
Java Web Services [2/5]: Introduction to SOAP
IMC Institute
 
Java Web Services [5/5]: REST and JAX-RS
Java Web Services [5/5]: REST and JAX-RSJava Web Services [5/5]: REST and JAX-RS
Java Web Services [5/5]: REST and JAX-RS
IMC Institute
 
Java Web Services [3/5]: WSDL, WADL and UDDI
Java Web Services [3/5]: WSDL, WADL and UDDIJava Web Services [3/5]: WSDL, WADL and UDDI
Java Web Services [3/5]: WSDL, WADL and UDDI
IMC Institute
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
Surinder Kaur
 
Java Web Services [1/5]: Introduction to Web Services
Java Web Services [1/5]: Introduction to Web ServicesJava Web Services [1/5]: Introduction to Web Services
Java Web Services [1/5]: Introduction to Web Services
IMC Institute
 
Web Technologies in Java EE 7
Web Technologies in Java EE 7Web Technologies in Java EE 7
Web Technologies in Java EE 7
Lukáš Fryč
 
Java Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web ServicesJava Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web Services
IMC Institute
 
Community and Java EE @ DevConf.CZ
Community and Java EE @ DevConf.CZCommunity and Java EE @ DevConf.CZ
Community and Java EE @ DevConf.CZ
Markus Eisele
 
Writing simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorWriting simple web services in java using eclipse editor
Writing simple web services in java using eclipse editor
Santosh Kumar Kar
 
Ad

Similar to Xml Java (20)

Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
BG Java EE Course
 
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Marco Gralike
 
my test
my testmy test
my test
lu jimmy
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
Guillaume Laforge
 
RESTful Services
RESTful ServicesRESTful Services
RESTful Services
Kurt Cagle
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-public
Timothy Perrett
 
Sax Dom Tutorial
Sax Dom TutorialSax Dom Tutorial
Sax Dom Tutorial
vikram singh
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Marco Gralike
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
Guillaume Laforge
 
UNO based ODF Toolkit API
UNO based ODF Toolkit APIUNO based ODF Toolkit API
UNO based ODF Toolkit API
Alexandro Colorado
 
IBM Solutions '99 XML and Java: Lessons Learned
IBM Solutions '99 XML and Java: Lessons LearnedIBM Solutions '99 XML and Java: Lessons Learned
IBM Solutions '99 XML and Java: Lessons Learned
Ted Leung
 
Apache Persistence Layers
Apache Persistence LayersApache Persistence Layers
Apache Persistence Layers
Henning Schmiedehausen
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
bcruhl
 
Modern JavaScript Programming
Modern JavaScript Programming Modern JavaScript Programming
Modern JavaScript Programming
Wildan Maulana
 
Introduction to Prototype JS Framework
Introduction to Prototype JS FrameworkIntroduction to Prototype JS Framework
Introduction to Prototype JS Framework
Mohd Imran
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
Rohan Chandane
 
Porting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPorting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQL
Peter Eisentraut
 
Intro to Talend Open Studio for Data Integration
Intro to Talend Open Studio for Data IntegrationIntro to Talend Open Studio for Data Integration
Intro to Talend Open Studio for Data Integration
Philip Yurchuk
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
John Brunswick
 
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Marco Gralike
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
Guillaume Laforge
 
RESTful Services
RESTful ServicesRESTful Services
RESTful Services
Kurt Cagle
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-public
Timothy Perrett
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Marco Gralike
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
Guillaume Laforge
 
IBM Solutions '99 XML and Java: Lessons Learned
IBM Solutions '99 XML and Java: Lessons LearnedIBM Solutions '99 XML and Java: Lessons Learned
IBM Solutions '99 XML and Java: Lessons Learned
Ted Leung
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
bcruhl
 
Modern JavaScript Programming
Modern JavaScript Programming Modern JavaScript Programming
Modern JavaScript Programming
Wildan Maulana
 
Introduction to Prototype JS Framework
Introduction to Prototype JS FrameworkIntroduction to Prototype JS Framework
Introduction to Prototype JS Framework
Mohd Imran
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
Rohan Chandane
 
Porting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPorting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQL
Peter Eisentraut
 
Intro to Talend Open Studio for Data Integration
Intro to Talend Open Studio for Data IntegrationIntro to Talend Open Studio for Data Integration
Intro to Talend Open Studio for Data Integration
Philip Yurchuk
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
John Brunswick
 
Ad

Recently uploaded (20)

TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 

Xml Java

  • 1. XML and Java Alex Chaffee, [email protected] http://www.purpletech.com
  • 2. Overview Why Java and XML? Parsers: DOM, JDOM, SAX Using XML from JSP Java/XML Object Mapping Resources
  • 3. Why Java/XML? XML maps well to Java late binding hierarchical (OO) data model Unicode support in Java XML Structures map well to Java Objects Portability Network friendly
  • 4. XML Parsers Validating/Non-Validating Tree-based Event-based SAX-compliance Not technically parsers XSL XPath
  • 5. Some Java XML Parsers DOM Sun JAXP IBM XML4J Apache Xerces Resin (Caucho) DXP (DataChannel) SAX Sun JAXP SAXON JDOM
  • 6. Dom API Tree-based Node classes Part of W3C spec Sorting/Modifying of Elements Sharing document with other applications
  • 7. XML is a Tree <?xml version=&quot;1.0&quot;?> <!DOCTYPE menu SYSTEM &quot;menu.dtd&quot;> <menu> <meal name=&quot;breakfast&quot;> <food>Scrambled Eggs</food> <food>Hash Browns</food> <drink>Orange Juice</drink> </meal> <meal name=&quot;snack&quot;> <food>Chips</food> </meal> </menu> menu meal name &quot;breakfast&quot; food &quot;Scrambled Eggs&quot; food &quot;Hash Browns&quot; drink &quot;Orange Juice&quot; meal
  • 8. DOM API (cont’d) Based on Interfaces Good design style - separate interface from implementation Document, Text, Processing Instruction, Element - ALL are interfaces All extend interface Node Including interface Attr (parentNode is null, etc)
  • 9. DOM Example public void print(Node node) { //recursive method call using DOM API... int type = node.getNodeType(); case Node.ELEMENT_NODE: // print element with attributes out.print('<'); out.print(node.getNodeName()); Attr attrs[] = node.getAttributes(); for (int i = 0; i < attrs.length; i++) { Attr attr = attrs[i]; out.print(' '); out.print(attr.getNodeName());out.print(&quot;=\&quot;&quot;); out.print(normalize(attr.getNodeValue())); out.print('&quot;'); } out.print('>'); NodeList children = node.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) { print(children.item(i)); } } break; case Node.ENTITY_REFERENCE_NODE: // handle entity reference nodes // ...
  • 10. DOM API Highlights Node getNodeType() getNodeName() getNodeValue() returns null for Elements getAttributes() returns null for non-Elements getChildNodes() getParentNode() Element getTagName() same as getNodeName() getElementsByTagName(String tag) get all children of this name, recursively normalize() smooshes text nodes together Attr attributes are not technically child nodes getParent() et al. return null getName(), getValue() Document has one child node - the root element call getDocumentElement() contains factory methods for creating attributes, comments, etc.
  • 11. DOM Level 2 Adds namespace support, extra methods Not supported by Java XML processors yet
  • 12. The Trouble With DOM Written by C programmers Cumbersome API Node does double-duty as collection Multiple ways to traverse, with different interfaces Tedious to walk around tree to do simple tasks Doesn't support Java standards (java.util collections)
  • 13. JDOM: Better than DOM Java from the ground up Open source Clean, simple API Uses Java Collections
  • 14. JDOM vs. DOM Classes / Interfaces Java / Many languages Java Collections / Idiosyncratic collections getChildText() and other useful methods / getNextSibling() and other useless methods
  • 15. JDOM: The Best of Both Worlds Clean, easy to use API document.getRootElement().getChild(&quot;book&quot;). getChildText(&quot;title&quot;) Random-access tree model (like DOM) Can use SAX for backing parser Open Source, not Standards Committee Allowed benevolent dictatorship -> clean design
  • 16. JDOM Example XMLOutputter out = new XMLOutputter(); out.output( element, System.out ); Or… public void print(Element node) { //recursive method call using JDOM API... out.print('<'); out.print(node.getName()); List attrs = node.getAttributes(); for (int i = 0; i < attrs.size(); i++) { Attribute attr = (Attribute)attrs.get(i); out.print(' '); out.print(attr.getName());out.print(&quot;=\&quot;&quot;); out.print(attr.getValue() ); out.print('&quot;'); } out.print('>'); List children = node.getChildren(); if (children != null) { for (int i = 0; i < children.size(); i++) { print(children.item(i)); } }
  • 17. JDOM Example public Element toElement(User dobj) throws IOException { User obj = (User)dobj; Element element = new Element(&quot;user&quot;); element.addAttribute(&quot;userid&quot;, &quot;&quot;+user.getUserid()); String val; val = obj.getUsername(); if (val != null) { element.addChild(new Element(&quot;username&quot;).setText(val)); } val = obj.getPasswordEncrypted(); if (val != null) { element.addChild(new Element(&quot;passwordEncrypted&quot;).setText(val)); } return element; }
  • 18. JDOM Example public User fromElement(Element element) throws DataObjectException { List list; User obj = new User(); String value = null; Attribute userid = element.getAttribute(&quot;userid&quot;); if (userid != null) { obj.setUserid( userid.getIntValue() ); } value = element.getChildText(&quot;username&quot;); if (value != null) { obj.setUsername( value ); } value = element.getChildText(&quot;passwordEncrypted&quot;); if (value != null) { obj.setPasswordEncrypted( value ); } return obj; }
  • 19. DOMUtils DOM is clunky DOMUtils.java - set of utilities on top of DOM http://www.purpletech.com/code Or just use JDOM
  • 20. Event-Based Parsers Scans document top to bottom Invokes callback methods Treats XML not like a tree, but like a list (of tags and content) Pro: Not necessary to cache entire document Faster, smaller, simpler Con: must maintain state on your own can't easily backtrack or skip around
  • 21. SAX API Grew out of xmldev mailing list (grassroots) Event-based startElement(), endElement() Application intercepts events Not necessary to cache entire document
  • 22. Sax API (cont’d) public void startElement(String name, AttributeList atts) { // perform implementation out.print(“Element name is “ + name); out.print(“, first attribute is “ + atts.getName(0) + “, value is “ + atts.getValue(0)); }
  • 23. XPath The stuff inside the quotes in XSL Directory-path metaphor for navigating XML document &quot;/curriculum/class[4]/student[first()]&quot; Implementations Resin (Caucho) built on DOM JDOM has one in the &quot;contrib&quot; package Very efficient API for extracting specific info from an XML tree Don't have to walk the DOM or wait for the SAX Con: yet another syntax / language, without full access to Java libraries
  • 24. XSL eXtensible Stylesheet Language transforms one XML document into another XSL file is a list of rules Java XSL processors exist Apache Xalan (not to be confused with Apache Xerces) IBM LotusXSL Resin SAXON XT
  • 25. Trouble with XSL It's a programming language masquerading as a markup language Difficult to debug Turns traditional programming mindset on its head Declarative vs. procedural Recursive, like Prolog Doesn't really separate presentation from code
  • 26. JSP JavaServer Pages Outputting XML <% User = loadUser(request.getParameter(&quot;username&quot;)); response.setContentType(&quot;text/xml&quot;); %> <user> <username><%=user.getUsername()%></username> <realname><%=user.getRealname()%></realname> </user> Can also output HTML based on XML parser, naturally (see my &quot;JSP and XML&quot; talk, or http://www.purpletech.com)
  • 27. XMLC A radical solution to the problem of how to separate presentation template from logic… …to actually separate the presentation template from the logic!
  • 28. XMLC Architecture HTML (with ID tags) Java Class (e.g. Servlet) HTML Object (automatically generated) XMLC HTML (dynamically-generated) Setting values Data Reading data
  • 29. XMLC Details Open-source (xmlc.enhydra.org) Uses W3C DOM APIs Generates &quot;set&quot; methods per tag Source: <H1 id=&quot;title&quot;>Hello</H1> Code: obj.setElementTitle(&quot;Goodbye&quot;) Output: <H1>Goodbye</H1> Allows graphic designers and database programmers to develop in parallel Works with XML source too
  • 30. XML and Java in 2001 Many apps' config files are in XML Ant Tomcat Servlets Several XML-based Sun APIs JAXP JAXM ebXML SOAP (half-heartedly supported  )
  • 31. Java XML Documentation Jdox Javadoc -> single XML file http://www.componentregistry.com/ Ready for transformation (e.g. XSL) Java Doclet http://www.sun.com/xml/developers/doclet Javadoc -> multiple XML files (one per class) Cocoon Has alpha XML doclet
  • 32. Soapbox: DTDs are irrelevant DTDs describe structure of an unknown document But in most applications, you already know the structure – it's implicit in the code If the document does not conform, there will be a runtime error, and/or corrupt/null data This is as it should be! GIGO. You could have a separate &quot;sanity check&quot; phase, but parsing with validation &quot;on&quot; just slows down your app Useful for large-scale document-processing applications, but not for custom apps or transformations
  • 34. Server-Side Java-XML Architecture Many possible architectures XML Data Source disk or database or other data feed Java API DOM or SAX or XPath or XSL XSL optional transformation into final HTML, or HTML snippets, or intermediate XML Java Business Logic JavaBeans and/or EJB Java Presentation Code Servlets and/or JSP and/or XMLC
  • 35. Server-Side Java-XML Architecture Java UI Java Business Logic XML Processors XML Data Sources HTML JSP JavaBeans Servlet EJB DOM, SAX XPath XSL Filesystem XML-savvy RDBMS XML Data Feed
  • 36. Server-Side Architecture Notes Note that you can skip any layer, and/or call within layers e.g. XML->XSL->DOM->JSP, or JSP->Servlet->DOM->XML
  • 37. Cache as Cache Can Caching is essential Whatever its advantages, XML is slow Cache results on disk and/or in memory
  • 38. XML <-> Java Object Mapping
  • 39. XML and Object Mapping Java -> XML Start with Java class definitions Serialize them - write them to an XML stream Deserialize them - read values in from previously serialized file XML -> Java Start with XML document type Generate Java classes that correspond to elements Classes can read in data, and write in compatible format (shareable)
  • 40. Java -> XML Implementations Java -> XML BeanML Coins / BML Sun's XMLOutputStream/XMLInputStream XwingML (Bluestone) JDOM BeanMapper Quick? JSP (must roll your own)
  • 41. BeanML Code (Extract) <?xml version=&quot;1.0&quot;?> <bean class=&quot;java.awt.Panel&quot;> <property name=&quot;background&quot; value=&quot;0xeeeeee&quot;/> <property name=&quot;layout&quot;> <bean class=&quot;java.awt.BorderLayout&quot;/> </property> <add> <bean class=&quot;demos.juggler.Juggler&quot; id=&quot;Juggler&quot;> <property name=&quot;animationRate&quot; value=&quot;50&quot;/> <call-method name=&quot;start&quot;/> </bean> <string>Center</string> </add> … </bean>
  • 42. Coins Part of MDSAX Connect XML Elements and JavaBeans Uses Sax Parser, Docuverse DOM to convert XML into JavaBean Uses BML - (Bindings Markup Language) to define mapping of XML elements to Java Classes
  • 43. JDOM BeanMapper Written by Alex Chaffee  Default implementation outputs element-only XML, one element per property, named after property Also goes other direction (XML->Java) Doesn't (yet) automatically build bean classes Can set mapping to other custom element names / attributes
  • 44. XMLOutputStream/XMLInputStream From some Sun engineers http://java.sun.com/products/jfc/tsc/articles/persistence/ May possibly become core, but unclear Serializes Java classes to and from XML Works with existing Java Serialization Not tied to a specific XML representation You can build your own plug-in parser Theoretically, can be used for XML->Java as well
  • 46.  
  • 47. XML -> Java Implementations XML -> Java Java-XML Data Binding (JSR 31 / Adelard) IBM XML Master (Xmas) Purple Technology XDB Breeze XML Studio (v2)
  • 48. Adelard (Java-XML Data Binding) Java Standards Request 31 Still vapor! (?)
  • 49. Castor Implementation of JSR 31 http://castor.exolab.org Open-source
  • 50. IBM XML Master (&quot;XMas&quot;) Not vaporware - it works!!! Same idea as Java-XML Data Binding From IBM Alphaworks Two parts builder application visual XML editor beans
  • 51. Brett McLaughlin's Data Binding Package See JavaWorld articles
  • 52. Purple Technology XDB In progress (still vapor) Currently rewriting to use JDOM JDOMBean helps Three parts XML utility classes XML->Java data binding system Caching filesystem-based XML database (with searching)
  • 53. Conclusion Java and XML are two great tastes that taste great together
  • 54. Resources XML Developments: Elliot Rusty Harold: Café Con Leche - metalab.unc.edu/xml Author, XML Bible Simon St. Laurent www.simonstl.com Author, Building XML Applications General www.xmlinfo.com www.oasis-open.org/cover/xml.html www.xml.com www.jdm.com www.purpletech.com/xml
  • 55. Resources: Java-XML Object Mapping JSR 31 http://java.sun.com/aboutJava/communityprocess/jsr/jsr_031_xmld.html http://java.sun.com/xml/docs/binding/DataBinding.html XMas http://alphaworks.ibm.com/tech/xmas
  • 56. Resources XSL: James Tauber: xsl tutorial: www.xmlsoftware.com/articles/xsl-by-example.html Michael Kay Saxon home.iclweb.com/icl2/mhkay/Saxon.html James Clark XP Parser, XT editor, XSL Transformations W3C Spec
  • 58. Thanks To John McGann Daniel Zen David Orchard My Mom