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 :
3156
The javax.xml.parsers.DocumentBuilderFactory Class
This class
provides the factory that
enables applications to create a parser to parse XML documents and also create
DOM Document. 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. This class is generally used to get javax.xml.parsers.DocumentBuilder
instance and use that to produce a org.w3c.dom.Document.
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(), newDocumentBuilder(),
setNamespaceAware(boolean awareness) and setValidating(boolean validating).
Example of newInstance()
This
method is used to create an instance of DocumentBuilderFactory. This is a
abstract class and newInstance method uses the lookup method to load
appropriate DocumentBuilderFactory. Generally
·
Use the value of javax.xml.parsers.DocumentBuilderFactory system
property.
You can set the system property as {your factory
class} = your factory class impl (It
may be org.apache.crimson.jaxp.DocumentBuilderFactoryImpl or
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl).
·
IfJRE/lib/jaxp.properties exists, then look for a
javax.xml.parsers.DocumentBuilderFactory = Implementation entry in the file.
·
Use a JAR file service provider to look for a file called
META-INF/services/ javax.xml.parsers.DocumentBuilderFactory in any jar file on
the CLASSPATH.
·
Use default javax.xml.parsers.DocumentBuilderFactory
instance(org.apache.crimson.jaxp.DocumentBuilderFactoryImpl will be used as a
default implementation).
By default, it loads
org.apache.crimson.jaxp.DocumentBuilderFactoryImpl instance.
Example of newDocumentBuilder()
This
method creates an instance of javax.xml.parsers.DocumentBuilder. You can use
newDocument() method to create a org.w3c.dom.Document interface or use parse()
method to parse xml from various xml sources. These input sources are
InputStreams, Files, URLs, and SAX InputSources.
Example of setValidating(boolean)
This
method is used to validate an xml document during parsing. By default it is false.
Example of setNamespaceAware(boolean). This method is
used to provide namespace aware for the parser and by default it is false.