BizTalk Utilities CV ,   Jobs ,   Code library  
 
javax.xml.parsers.SAXParser Class
javax.xml.parsers.DocumentBuilderFactory Class
javax.xml.parsers.DocumentBuilder Class
SAX 2.0 Features and Properties
MSMQ Mode Tool
XML for Software Configuration
XML - Basics.
RTF to XML converter 1.2
Retriving XML from a Oracle Table using the XDK for PL/SQL
'AspDoc' - Documenting your ASP code with XML
Password Encryption
Inserting Data in XML format into a table using Oracle XML SQL Utility
Java Architecture for XML Binding
XML to JTree
QuickBooks XML SDK
x++: The World's First Full XML-Based Programming Language Released!
Mobile Internet
Applying XML Patterns
shortx: New C like Syntax for x++
Witango XML Execution Engine
<< XSLT
.NET and XML >>

By :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

import javax.xml.parsers.SAXParserFactory;

import javax.xml.parsers.SAXParser;

public class SaxParserFactoryImplementation {

  public SaxParserFactoryImplementation() {

    SAXParserFactory factory = SAXParserFactory.newInstance();

   }

}

Example for implementation of newSAXParser() method

import javax.xml.parsers.SAXParserFactory;

import javax.xml.parsers.SAXParser;

public class SaxParserFactoryImplementation {

  public SaxParserFactoryImplementation() {

    SAXParserFactory factory = SAXParserFactory.newInstance();

    try{

      SAXParser saxParser = factory.newSAXParser();

     

    }catch(javax.xml.parsers.ParserConfigurationException e){

      e.printStackTrace();

    }

   }

}


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C
Immediate ASP.NET/C# Openings for C

View all Jobs (Add yours)
View all CV (Add yours)



help desk support
swimming pool contractor
conference call
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP