Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

What is the difference between ..

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jaxp and Xerces ? I have a xml file with say customer-name and customer-action that I need to read with a command line java program and then act upon the database to add/delete or modify the name based on action..
What are the components I need for reading this xml file and using the values in it as keys for my db lookup ?
Thanks !
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JAXP, the "Java API for XML Parsing" provides a framework to both SAX and DOM XML parsers. Xerces provides an implementation of a SAX and DOM parser.
JAXP on its own does nothing. What is provides is a neutral manner in which to change what parser you are using. For example, let's say you are using Xerces on a project that parses an XML document to determine what stock is on hand at a retail store. Doing so requires references to the org.apache.xerces.parsers.SAXParser class. Let's say that you want to move this parsing onto a small mobile device like a cell phone. You can't use Xerces because it has too large a memory footprint. Now you have to go through all of your code and change all calls to Xerces to whatever other parser you need to use. If you used a framework like JAXP all that you would need to to is change a system property and the new parser would be used instead of Xerces.
The application you have in mind sounds like a perfect paradigm for using SAX. Based on a particular XML element, you want to perform an action. You would define your ContentHandler to intercept <customer-name> elements. You would then wait for a <customer-action> element and then fire the appropriate action on the database.
In the "Professional Java XML" book there is an example program that uses SAX in a similiar manner. The State pattern is used in the case where how you handle events is context-sensitive (in this case performing an action based on the user name read previously).

------------------
Jeremy Crosbie
Co-Author of Professional Java XML
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JAXP is an API that simplifies using (particularly instantiating) different XML parsers that implement the DOM or SAX APIs. It is not a parser itself but more of a framework that allows you to easily plug in the parser you want to use.
Xerces is a particular XML parser implementation, in this case from the Apache group. You can use it with JAXP, and you can also use other implementations, for example from IBM or SUN. Most parsers implement both SAX and DOM.
In your case, i.e. for parsing customer data and operating on it without having to modify the XML file, it sounds like you might want to use a SAX parser for efficiency purposes.
-Mirko

Originally posted by Mak Bhandari:
Jaxp and Xerces ? I have a xml file with say customer-name and customer-action that I need to read with a command line java program and then act upon the database to add/delete or modify the name based on action..
What are the components I need for reading this xml file and using the values in it as keys for my db lookup ?
Thanks !


 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Sir,
Thank you for the clarification. I am a newbie and I found your post helpful. I can change parsers as long as I use the JAXP framework, right? Ok, so JAXP is a framework and it allows me to use any parser.
What is better to use? Crimson or Xerces?
Is there an introductory article on how to use all of these (JAXP/Crimson or Xerces)?
 
reply
    Bookmark Topic Watch Topic
  • New Topic