advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Can you think of other ways to use the JAXP parser created in this article? How might you make use of JAXP's flexibility in your organization? Tell us in the java.general discussion group.
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 5/5 | Rate this item | 2 users have rated this item.
 

Transform Legacy Data to XML Using JAXP

By writing to the JAXP specification, Java developers can create extensible code routines to parse any type of data into XML. This tutorial shows you how to write your own JAXP-compliant parser to transform legacy data in a comma-separated value (CSV) format, output it to a DOM, and then transform into XML. 


advertisement
he ability to parse and transform XML documents is nothing new for Java developers. There are several packages available that come with the tools to do it. But these products all have incompatible implementations, so once you start using one package, you're locked in.


Sun Microsystems has attacked this problem by creating interfaces for many different aspects of XML programming. One of the packaged interfaces Sun created is the Java API for XML Processing (JAXP), which is part of its early release XML pack. JAXP abstracts both XML parsing and transformations. Thus, writing your XML processing code using JAXP will make it portable to any other implementation that supports JAXP. As of this writing, the XML pack comes with Xerces2, XalanJ, and Crimson, which all support JAXP. Many people consider Apache's Xerces2 and XalanJ to be the de facto standards for Java XML processing anyway, so their support for JAXP is no surprise.

In this article I will show you how to create your own legacy data parser using JAXP. Why write a parser for a non-XML document using JAXP? I want to show how to transform a legacy data file into an XML document. By using JAXP to parse the file I will be able to create a DOM representation of it, which can then easily be transformed to XML.

Later in the article, I will demonstrate a simple XML transformation using JAXP. I'll use the legacy data parser created in the first part of the article to transform a comma-separated value (CSV) file into an XML document. Because the transformation uses JAXP, the code will never have to change so long as the parser you use conforms to JAXP's interface.
  Next Page: Writing the Parser


Page 1: IntroductionPage 3: Abstraction and Reuse
Page 2: Writing the Parser Page 4: Doing the XML Transformation
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs