BizTalk Utilities CV ,   Jobs ,   Code library  
 
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
javax.xml.parsers.SAXParser Class
javax.xml.parsers.DocumentBuilderFactory Class
javax.xml.parsers.DocumentBuilder 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 :177

 

Overview of Content Handlers

There are four core handler interfaces defined by SAX 2.0: org.xml.sax.ContentHandler, org.xml.sax.ErrorHandler, org.xml.sax.DTDHandler, and org.xml.sax.EntityResolver. In this scenario we discuss ContentHandler, which allows standard data-related events within an xml document to be handled, and take a first look at ErrorHandler, which receives notifications from the parser when errors in the xml data are found. DTDHandler will be examined in later discussion.

The org.xml.sax.ContentHandler Interface

All Known Subinterfaces: javax.xml.transform.sax.TemplatesHandler, javax.xml.transform.sax.TransformerHandler.
All Known Implementing Classes: org.xml.sax.helpers.DefaultHandler, org.xml.sax.helpers.XMLFilterImpl, org.xml.sax.helpers.XMLReaderAdapter

Public Members

Signature

Public methods

void

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

void

endDocument()

void

endElement(String namespaceURI, String localName, String qName)

void

endPrefixMapping(String prefix)

void

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

void

setDocumentLocator(Locator locator)

void

skippedEntity(String name)

void

startDocument()

void

startElement(String namespaceURI, String localName, String qName, Attributes atts)

void

startPrefixMapping(String prefix, String uri)

Overview

This is a public interface so user needs to create a class wrapped on this interface. Receive notification of the logical content of a document. This is the main interface that most SAX applications implement: if the application needs to be informed of basic parsing events, it implements this interface and registers an instance with the SAX parser using the setContentHandler method of org.xml.sax.XMLReader or parse(inputsource/file, ContentHandler) method of SAXParser. The parser uses the instance to report basic document-related events like the start and end of elements and character data.

The order of events in this interface is very important, and mirrors the order of information in the document itself. For example, all of an element's content (character data, processing instructions, and/or subelements) will appear, in order, between the startElement event and the corresponding endElement event.

This interface is similar to the now-deprecated SAX 1.0 DocumentHandler interface, but it adds support for Namespaces and for reporting skipped entities (in non-validating XML processors).

Method Overview

Most of the methods in this interface are important and depends upon the requirement of your application. To know more details, please refer the example with method description.

Example:

/**

 * <p>Title: MyContentHandler.java</p>

 * <p>Description: MyContentHandler implements the SAX ContentHandler interface

 *  and defines callback behaviour for the SAX callbacks associated with

 *  an XML documents content.</p>

 */

import org.xml.sax.Attributes;

import org.xml.sax.ContentHandler;

import org.xml.sax.Locator;

import org.xml.sax.SAXException;

import org.xml.sax.XMLReader;

public class MyContentHandler implements ContentHandler{

  /**

   * This reports character data within an element.

   * @param ch

   * @param start

   * @param length

   */

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

 }

 /**

  * This indicates the end of a Document parse-this occurs after all callbacks

  * in all SAX Handlers.

  */

 public void endDocument() {

 }

 /**

  * Indicates the end of an element </elementname> is reached. Note that the parser

  * does not distinguish between empty elements and non empty elements, so this

  * occurs uniformly.

  * @param namespaceURI

  * @param localName

  * @param qName

  */

 public void endElement(String namespaceURI, String localName, String qName){

 }

 /**

  * This indicates the end of a prefix mapping, when the namespace reported in a

  *  #startPrefixMapping call back is no longer available.

  * @param prefix

  */

 public void endPrefixMapping(String prefix) {

 }

 /**

  * This reports whitespace that can be ignored in the originating document.

  * This is typically invoked only when validation is occurring in the parsing

  * process.

  * @param ch

  * @param start

  * @param length

  */

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

 }

 /**

  * This indicates that a processing instruction (other tahn the xml declaration)

  * has been encountered.

  * @param target

  * @param data

  */

 public void processingInstruction(String target, String data){

 }

 /**

  * Provides references to Locator which provides information about where in

  * a document callbacks occur.

  * @param locator

  */

 public void setDocumentLocator(Locator locator){

 }

 /**

  * This reports an entity that is skipped by the parser. This should only occur

  * for non-validating parsers, and then is still implementation-dependent behaviour.

  * @param name

  */

 public void skippedEntity(String name){

 }

 /**

  * This indicates the start of a document parse-this precedes all callbacks

  * in all SAX handlers with the sole exception of setDocumentLocator.

  */

 public void startDocument(){

 }

 /**

  * This reports the occurence of an actual element. It includes the elements

  * attributes, with the exception of XML vocabulary specific attributes, such as

  * xmlns:[namespace prefix] and xsi:[schemaLocation]

  * @param namespaceURI

  * @param localName

  * @param qName

  * @param atts

  */

 public void startElement(String namespaceURI, String localName, String qName, Attributes atts){

 }

 /**

  * This indiacates the beginning of an xml Namespace prefix mapping. Although

  * this typically occurs within the root element of an XML document, it can occur

  * at any point within the document. Note that prefix mappings of an element

  * triggers this callback before the callback for the actual element itself

  * #startElement occurs.

  * @param prefix

  * @param uri

  */

 public void startPrefixMapping(String prefix, String uri){

 }

}


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)



online fax
swimming pool contractor
United Kingdom Conference Calling
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