Here’s the code:
SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
Why use that if you can use something more intuitive like:
SAXParser mySAXParser = new SAXParser();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because this allows the framework to provide you with different implementations of
SAXParserin a transparent way. The implementation used may depend on configuration parameters, framework version etc. Using a factory allows the framework developers e.g. to replace an old, inefficient parser implementation with a different, better one, without breaking any client code.Note that
SAXParseris an abstract class, so you can’t even instantiate it directly.