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

 

The org.xml.sax.ext.LexicalHandler Handler

All Known Subinterfaces: java.xml.transform.sax.TransformerHandler

Members

Signature

Public methods

void

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

void

endCDATA()

void

endDTD()

void

endEntity(String name)

void

startCDATA()

void

startDTD(String name, String publicId, String systemId)

void

startEntity(String name)

Overview

This interface defines callback methods that can receive notification of several lexical events such as comments, entity declarations, DTD declarations, and CDATA sections. This does not affect the resulting data within the XML document. In ContentHandler, these lexical events are essentially ignored, and you just get the data and declarations without notification of when or how they were provided.

This is not really a general-use handler, as most applications don’t need to know if text was in a CDATA section or not. However, if you are working with an XML editor, serializor, or just its contents, the LexicalHandler can really help you out.

Method Overviews

As I have already mentioned in the overview, methods in this interface receives notification for lexical events. We generally don’t use this interface in our parsers but for advance use, I have given examples of methods which I generally use in my application.

Example of comment()

Report an XML comment anywhere in the document. This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read). Comments in the DTD must be properly nested inside start/endDTD and start/endEntity events (if used).

/**

   * Report an XML comment anywhere in the document.

   * @param ch An array holding the characters in the comment.

   * @param start The starting position in the array.

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

   */

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

  {

    System.out.println("Start of comment");

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

    System.out.println("End of comment");

  }

Example of elementDecl()

/**

   * This method reports an element type declaration(<!ELEMENT) in DTD.

   * @param name The element type name.

   * @param model The content model as a normalized string.

   */

  public void elementDecl(String name, String model)

  {

    System.out.println("Start of elementDecl");

    System.out.println("name :"+name);

    System.out.println("model :"+model);

    System.out.println("End of elementDecl");

  }

Example of startDTD()

Report the start of DTD declarations, if any. This method is intended to report the beginning of the DOCTYPE declaration; if the document has no DOCTYPE declaration, this method will not be invoked.

/**

   * Report the start of DTD declarations, if any.

   * @param name The document type name.

   * @param publicId The declared public identifier for the external DTD subset, or null if none was declared.

   * @param systemId The declared system identifier for the external DTD subset, or null if none was declared.

   */

  public void startDTD(String name, String publicId, String systemId)

  {

    System.out.println("startDTD");

    System.out.println("name :"+name);

    System.out.println("public Id :"+publicId);

    System.out.println("System Id :"+systemId);

  }

Example of How to use LexicalHandler

   LexicalHandlerImpl lexicalHandler = new LexicalHandlerImpl();//This class implements LexicalHandler

/*

To set the LexicalHandler for an XML reader, use the setProperty method with the propertyId "http://xml.org/sax/properties/lexical-handler". If the reader does not support lexical events, it will throw a SAXNotRecognizedException or a SAXNotSupportedException when you attempt to register the handler.

*/

    parser.setProperty("http://xml.org/sax/properties/lexical-handler",lexicalHandler);

/**

*Before using this ensure that your xml file contains DOCTYPE declaration with a DTD.

**/

<!DOCTYPE purchaseOrder SYSTEM "E:\topxml\purchaseorder.dtd">


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

An immediate job opportunity as a B
Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C

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



answering service
online fax service
swimming pool contractor
teleconferencing services
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