Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
321
The javax.xml.parsers.SAXParserFactory Class
Super Class :
java.lang.Object.
Public Members
Signature
Public methods
abstract boolean
getFeature(String name)
boolean
isNamespaceAware()
boolean
isValidating()
static SAXParserFactory
newInstance()
abstract SAXParser
newSAXParser()
abstract void
setFeature(String name, boolean value)
void
setNamespaceAware(boolean awareness)
void
setValidating(boolean validating)
Overview
This is an abstract class. Defines a factory
API that enables applications to configure and obtain a SAX based parser to
parse XML documents. This
class is not thread safe and user should take care regarding creation of
DocumentBuilderFactory and it is suggested to have one instance per Thread and
user should ensure that the same instance is not used across more than one
thread to create SAXParser. This
class is generally used to get javax.xml.parsers.SAXParser.
Application code does not deal
directly with specific parse implementation such as Xerces or Crimson. Instead
you write code against abstract classes provided by JAXP apis. This level of
indirection allows you to choose and pick among different implementation
without even recompiling your application.
Method Overviews
Important methods of this class
are newInstance(), newSAXParser(), setNamespaceAware(boolean
awareness) and setValidating(boolean validating).
Example of newInstance()
This method
is used to create a new concrete implementation of this class. This is a
abstract class and newInstance method uses the lookup method to load
appropriate SAXParserFactory. Following lookup procedure is used create a
concrete implementation of SAXParserFactory.
·
Use the value of javax.xml.parsers. SAXParserFactory system property.
You can set the system property as {your factory class}
= your factory class impl (It may be org.apache.crimson.jaxp.SAXParserFactoryImpl
or org.apache.xerces.jaxp.SAXParserFactoryImpl). You can set this system
property to any api implementation depending upon your requirement.
·
IfJRE/lib/jaxp.properties exists, then look for a javax.xml.parsers.SAXParserFactory
= Implementation entry in the file.
·
Use a JAR file service provider to look for a file called
META-INF/services/ javax.xml.parsers.SAXParserFactory in any jar file on the
CLASSPATH.
·
Use default javax.xml.parsers. SAXParserFactory instance(org.apache.crimson.jaxp.SAXParserFactoryImpl
will be used as a default implementation).
By default, it loads org.apache.crimson.jaxp. SAXParserFactoryImpl
instance. You can find this class in lib/rt.jar file.
1)
newSAXParser(). This method creates an instance of javax.xml.parsers.SAXParser
using the currently configured factory parameters.
2)
setValidating(boolean). This method is used to validate an xml document
during parsing. By default it is false.
3)
setNamespaceAware(boolean). This method is used to provide namespace
aware for the parser and by default it is false.
Example for implementation of newInstance() method