Home > SOA Tips > XML Developer > A look inside the Java API for XML Processing
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

XML DEVELOPER

A look inside the Java API for XML Processing


William Brogden
11.02.2005
Rating: -4.00- (out of 5)


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


At one time, programmers trying to process XML with Java programs had to hunt around for one or more libraries from Sun, the Apache Software Foundation, or some other source to add to their Java programming environment. However, beginning with Java 1.4, most XML processing tasks can be handled with the classes in the standard edition and Java 1.5 adds many new tools. If you are looking for an excuse to move your Java development to 1.5, the built in XML capabilities may be all you need.

The basic division in XML processing is between approaches that give continued access to the entire document at once and those which take a single "streaming" pass through the document. Java provides the Java API for XML Processing or JAXP API which includes a standardized API for both types of processing. JAXP 1.3 is the latest version, finalized in September of 2004. It is implemented in the Java 1.5 Standard Edition release.

JAXP is designed to be an implementation-independent, portable API, meaning that any vendor's parser toolkit that meets the API specification can be plugged into a program that is written to the API. In practice, you will probably find the parser that comes with the Java Standard Edition to be satisfactory.

Most people easily grasp the Document Object Model or DOM since it presents a hierarchical or "tree" structure like that used in HTML and XHTML documents. In this approach, the entire document is read into memory where each node can be examined and manipulated. The key Java package for DOM manipulation is org.w3c.dom where the "org.w3c" reflects the fact that the implementation follows the World-Wide Web Consortium XML DOM standard.

The key interface within the org.w3c.dom package is Node. In a DOM representation, all elements in an XML document are objects that inherit the Node interface or a sub interface. For example, there are interfaces representing elements, attributes, text and comments. A DOM consists of a collection of Java objects linked together so that they represent the entire contents of the source XML document. The JavaDocs for the Node interface have a table showing the properties of objects implementing these interfaces. You should become familiar with this table before writing Java code to use the DOM.

The advantages of the DOM programming model are that every element can be located, manipulated and changed very efficiently. The disadvantages of working with a DOM are the processing time and memory required. Even if you only need access to a single element in the XML document, you have to parse the entire document into memory. As documents get larger, DOM processing becomes less practical.

Programming with a streaming parser is not as obvious, but it provides many advantages. A streaming parser takes a single pass through the document and deals with one element at a time. It is up to the programmer to decide which information to keep and which to ignore. The streaming parser in the JAXP library is called SAX for Simple API for XML. SAX was developed for Java outside the W3C standardization effort by David Megginson. The key package in the Java library for SAX programming is org.xml.sax.

As a SAX parser works its way through an XML document it generates events that represent the various elements it encounters. Programming for SAX processing consists of creating the classes and methods to handle these events and extract the desired information.

The Java standard edition provides other XML related APIs to make working with XML in Java easier and faster. All of these tools build on the JAXP foundation. However, discussion of these advanced tools will have to wait for another tips column.

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




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

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