BizTalk Utilities CV ,   Jobs ,   Code library  
 
org.xml.sax.ext.LexicalHandler Handler
org.xml.sax.ext.DeclHandler Handler
Overview of Content Handlers
Overview of DTD Handlers
java.xml.sax.InputSource Class
org.xml.sax.helpers.XMLReaderFactory Class
javax.xml.transform.URIResolver Class
javax.xml.transform.TransformerFactory Class
javax.xml.transform.Transformer Class
javax.xml.transform.Templates Class
javax.xml.transform.stream.StreamSource Class
javax.xml.transform.stream.StreamResult Class
javax.xml.transform.Source Class
javax.xml.transform.sax.SAXSource Class
javax.xml.transform.sax.SAXResult Class
javax.xml.transform.Result Class
javax.xml.transform.ErrorListener Class
javax.xml.transform.dom.DOMSource Class
javax.xml.transform.dom.DOMResult Class
javax.xml.parsers.SAXParserFactory Class
<< 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 :160

 

The org.xml.sax.HandlerBase Handler

All Known Implemented Interfaces: org.xml.sax.DocumentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, and org.xml.sax.ErrorHandler

Members

Signature

Public methods

void

characters(char[] ch, int start, int length)

void

endDocument()

void

endElement(String name)

void

error(SAXParseException e)

void

fatalError(SAXParseException e)

void

ignorableWhitespace(char[] ch, int start, int length)

void

notationDecl(String name, String publicId, String systemId)

void

processingInstruction(String target, String data)

InputSource

resolveEntity(String publicId, String systemId)

void

setDocumentLocator(Locator locator)

void

startDocument()

void

startElement(String name, AttributeList attributes)

void

unparsedEntityDecl(String name, String publicId, String systemId, String notationName)

void

warning(SAXParseException e)

Overview

This helper class provides empty implementation of all SAX 1.0 core handler interfaces, and can be extended to allow addition of handlers by overriding methods with application-defined behavior. This class was defined in SAX 1.0, and is now deprecated. The org.xml.sax.helpers.DefaultHandler class should be used instead of HandlerBase for SAX 2.0 implementations.

            To use JAXP with SAX-compliant parser, your only task is to extend the HandlerBase class and implement the callbacks desired for your application. The alternative in SAX 2.0 is doing the same with DefaultHandler. An instance of your extension class then becomes the core argument for most of the JAXP methods that deals with SAX.

Here’s the typical SAX rundown:

  • Create a SAXParser instance using  a specific vendor’s parser implementation.
  • Register callback implementations (by using  a class that extends HandlerBase)
  • Start parsing and relax as your callback implementations are fired off.
  • You only need to implement those callback methods of HandlerBase, that needed for your application.

The SAX component of JAXP provides a simple means to do all of this. Without JAXP, a SAX parser instance either must be instantiated directly from a vendor class ( such as org.apache.xerces.parsers.SAXParser), or it must use a SAX helper class called ParserFactory ( the SAX 1.0 version of SAX 2.0’s XMLReaderFactory).

The JAXP provides a better alternative. It allows you use the vendor class as a parser through a java system property. Please refer your vendor’s documentation for more details regarding the parser factory.

Method Overviews

All most all methods in this class are important. It depends upon your applications needs regarding what are the methods you need to implement in your parser mechanism. Some of the methods are generally used across all SAX parsers. I have listed the methods, those are commonly used across all SAX parsers.

Example of startDocument()

/**

   * This method receives notification, at the start of the XML Document.

   */

  public void startDocument()

  {

    System.out.println("Start of the Document");

  }

Example of startElement()

/**

   * This method receives notification at the start of each element of XMl Document for SAX parser.

   * @param name name of the element

   * @param attributes attributes associated with the element.

   */

  public void startElement(String name, AttributeList attributes)

  {

    System.out.println("Start of the element and Element Name :"+name);

    for (int i = 0; i < attributes.getLength(); i++) {

     String attrname = attributes.getName(i);

     String attrtype = attributes.getType(i);

     String attrvalue = attributes.getValue(i);

     System.out.println("Attribute Name :"+attrname);

     System.out.println("Attribute Type :"+attrtype);

     System.out.println("Attribute Value :"+attrvalue);

   }

  }

Example of characters()

/**

   * Receive notification of character data inside an element.

   * @param ch The characters.

   * @param start The start position in the character array.

   * @param length The number of characters to use from the character array.

   */

  public void characters(char[] ch, int start, int length)

  {

    System.out.println(" Character :"+new String(ch, start,length));

  }

}

Example of How to use HandlerBase

SAXParser parser = SAXParserFactory.newInstance().newSAXParser();

 HandlerBase handlerBase = new HandlerBaseImpl(); //This class extends HandlerBase

parser.parse({InputSource},handlerBase);


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

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

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



international conference call
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses
it help desk


    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