Home > SOA Tips > XML Developer > Alternatives to JAXP
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

XML DEVELOPER

Alternatives to JAXP


William Brogden
11.15.2005
Rating: -3.92- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


The previous tip in this series discussed the XML handling classes in the Java standard edition known as JAXP, the Java API for XML Processing. Now I am going to look at two popular alternatives and explain why some Java programmers prefer them.

JDOM as a substitute for DOM

The originators of the JDOM project, Jason Hunter and Brett McLaughlin, felt that the W3C programming API for the Document Object Model, or DOM, as used in the JAXP toolkit, was "ridiculously complex" and used programming idioms that were uncomfortable for most programmers. The design objective for JDOM was to make it easy to accomplish the most common tasks when reading and creating XML while making maximum use of familiar Java features. After serveral years of development version 1.0 of JDOM was released in 2004.

JDOM uses Java objects and is thus specific to Java rather than the generalized definition of the org.w3c.dom interfaces. However, JDOM is not a complete substitute for JAXP. It does not contain a parser, but uses any SAX parser that is compatible with the JAXP API. Furthermore, features are provided which let JDOM code cooperate with code written to the JAXP toolkit. For example, there are simple methods to convert a JDOM model of a document to or from a DOM model.

JDOM uses Java language features programmers are used to working with. For example, collections of XML elements can manipulated with the familiar List and Iterator interfaces. In contrast, the W3C programming model in JAXP represents a collection of Node objects with the NodeList interface which uses ungainly access methods.

In my opinion, JDOM will be most attractive to Java programmers who need to produce XML documents as quickly and simply as possible. Creation of objects representing XML elements is simple and logical, and combining elements into a complete document is straightforward. Output of a document or a portion of a document to a file, String object, or stream s...


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
XML Developer
Use the soapUI software tool to tame WSDL
WSDL 2.0, new messaging for Web services
Using RELAX NG For data integration
Efficient XML Interchange tackles data verbosity
XML to DDL imports, synchronizes database schemata
The basics of MathML 3.0
Migrating to XSLT 2.0
What's up with XML 2.0?
Say hello to XPath 2.0
Podcasting software covers many bases

XML and XML schema
What's the future of XML?
SOA pattern of the week (#7): policy centralization
Try XML-based Extensible Business Reporting Language (XBRL) for accounting reports
What's new at the W3C
Ganymede: Modeling tools target SOA, UML
Data services mashups emerge for SOA
Making sense of data services mashups
XML turns 10
SOA helps save 100-year-old business
Oracle maps heterogeneous data services strategy for SOA

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
class diagram  (SearchSOA.com)
Fast Infoset (FI)  (SearchSOA.com)
GeoRSS  (SearchSOA.com)
Keyhole Markup Language  (SearchSOA.com)
RELAX NG  (SearchSOA.com)
state diagram  (SearchSOA.com)
Universal Business Language  (SearchSOA.com)
Vector Markup Language  (SearchSOA.com)
XML infoset  (SearchSOA.com)
XML pipeline  (SearchSOA.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


uch as a network connection is conveniently handled by the XMLOutputter class.

StAX as a substitute for SAX

When using SAX to handle an XML document, the programmer connects a class with event handler methods to the parser and hands control to the parser. For each component of the XML document the parser encounters, it calls a matching event handler method, with control returning to the parser after the event is handled. This puts the programmer in the position of always responding to external events, a programming style that many find unnatural and inconvenient. An example of the inconvenience is thatto stop the parser you have to throw an exception in an event handling method.

SAX is called a "push" parser because it pushes events to the programmer's event handling code. The intent of StAX is to reverse the control. Once a StAX parser has been created, the programmer requests the next event from it so StAX is a "pull" parser.

A request for the next event gets you a Java object that implements some extension of the XMLEvent interface. These specific interfaces serve the same function as the specific event handler methods used in SAX, they tell you what type of XML markup the parser has encountered and contain information extracted from it. For example, the SAX method startElement() is called with parameters for the name and attribute contents of the element.With StAX, the event object would implement the StartElement interface which contains methods to get at the same information.

One feature of StAX that simplifies programming is the ability to "peek" at the next event without consuming it. This lets the programmer transfer control to the most appropriate method for the waiting event. With SAX programming the method that gets an event has to deal with it immediately, there is no way to put it off. StAX offers so many advantages that a toolkit implementing StAX is expected to become part of thenext major Java version and it is currently part of Sun's Web Services Developer Pack.

Resources

JDOM version 1.0 either as compiled code or with complete source is available from the http://www.jdom.org/ site. An extended discussion with many examples can be found in Jason Hunter's book "Processing XML with Java." A proposal to incorporate JDOM in the Java standard library is being handled by JSR-102 but it does not seem to have made much progress.

The official API for StAX is defined by JSR-173, which was finalized in March 2004. A reference version is available from http://dev2dev.bea.com/xml/stax.html.

About the author
Bill Brogden is a computer consultant who enjoys exploring new technologies. He has written study guides for Java certifications and several books on using XML with Java. You can reach Bill at wbrogden@bga.com.


Rate this Tip
To rate tips, you must be a member of SearchSOA.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



SOA Trends and Strategy - SOA Education, SOA Development, SOA Implementations
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2001 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts