This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

A very basic JAXP example  RSS feed

Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all experts,
Now I am studying the JAXP, and through some studies, I have theoratically come to adhering to the idea that JAXP allows other vendor-specific XML parsers to be plugged into it, and that we do not have to change the code, when we change the underlying XML parser (for example, from Apache's Xerces to IBM's xml4j). However, in the following code that I read when surfing the IBM's developer network, the vendor-specific API code does explicitly appears in the source code, that sparks a lot of confusion, could you clarify that?

******************************************************************************* *******************
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;

// SAX
import org.xml.sax.AttributeList;
import org.xml.sax.HandlerBase;
import org.xml.sax.SAXException;

public class TestSAXParsing {
public static void main(String[] args) {
try {
if (args.length != 1) {
System.err.println ("Usage: java TestSAXParsing [filename]");
System.exit (1);
// Get SAX Parser Factory
SAXParserFactory factory = SAXParserFactory.newInstance();
// Turn on validation, and turn off namespaces
SAXParser parser = factory.newSAXParser();
parser.parse(new File(args[0]), new MyHandler());
} catch (ParserConfigurationException e) {
System.out.println("The underlying parser does not support " +
" the requested features.");
} catch (FactoryConfigurationError e) {
System.out.println("Error occurred obtaining SAX Parser Factory.");
} catch (Exception e) {
class MyHandler extends HandlerBase {
// SAX callback implementations from DocumentHandler, ErrorHandler, etc.

Thanks a lot!
Posts: 11962
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this is an XML question and not specific to web services, I'm moving this thread over to our XML forum. Please continue the discussion over there.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!