Yesterday I have read the documentation related with SAX2 API class XMLReaderFactory and SAXParserFactory of JAXP API. Both of them used to serve the same purpose of providing the instance of the XMLReader class. Then I have gone through the various materials to understand the difference between the two and which would be more useful in a particular scenario.
Most of the materials I have read regarding the above question stated the below difference.
The problem with the helper class XMLReaderFactory method createXMLReaderFactory(String className) is that the factory requires, as an argument, the String name of the parser class to use (that Apache class, org.apache.xerces.parsers.SAXParser, again). You can change the parser by passing in a different parser class as a String. With this approach, if you change the parser name, you won't need to change any import statements, but you will still need to recompile the class. This is obviously not a best-case solution. It would be much easier to be able to change parsers without recompiling the class.
JAXP offers that better alternative: It lets you provide a parser as a Java system property. Of course, when you download a distribution from Sun, you get a JAXP implementation that uses Sun's version of Xerces. Changing the parser -- say, to Oracle's parser -- requires that you change a classpath setting, moving from one parser implementation to another, but it does not require code recompilation. And this is the magic -- the abstraction -- that JAXP is all about. Can anybody tell me in which particular scenario usage of particular method would become more useful
But I don't agree with the above difference since if we are using the method createXMLReaderFactory(String className) and instead of passing the class name directly to the method , if we read the name of the class from the properties file and pass it to the method then we don't need to recompile the class.
Please do let me know if I am correct on the above point or not.
Can anybody tell me the difference between the SAX2 API class XMLReaderFactory and SAXParserFactory of JAXP API?