Java
  Home arrow Java arrow Extension Interfaces and SAX
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Extension Interfaces and SAX
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 4
    2007-07-19

    Table of Contents:
  • Extension Interfaces and SAX
  • Extension Interfaces
  • XMLFilters continued
  • XMLWriter

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Extension Interfaces and SAX


    (Page 1 of 4 )

    In this conclusion to a three-part article, we look at extension interfaces, XML filters, and more as they relate to the Simple API for XML (SAX). This article is excerpted from chapter four of the book Java and XML, Third Edition, written by Brett McLaughlin and Justin Edelson (O'Reilly, 2006; ISBN: 059610149X). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

    DeclHandler

    A lesser used interface, DeclHandler is another of the extended SAX interfaces. This interface defines methods that receive notification of specific events within a DTD, such as element and attribute declarations. This is another item only good for very specific cases; again, XML editors and components that must know the exact lexical structure of documents and their DTDs come to mind. I’m not going to show you an example of using the DeclHandler ; at this point you know more than you’ll probably ever need to about handling callback methods. Instead, I’ll just give you a look at the interface, shown in Figure 4-6.

    The DeclHandler interface is fairly self-explanatory. The first two methods handle the <!ELEMENT> and
    <!ATTLIST> constructs. The third, externalEntityDecl() , reports entity declarations (through <!ENTITY> ) that refer to external resources. The final method, internalEntityDecl() , reports entities defined inline. That’s all there is to it.


    Figure 4-6.  The Dec1Handler interface isn't used often, but it's a real boon if you need to write code that deals directly with DTDs

    Attributes2, Locator2, and EntityResolver2

    SAX provides three other interesting interfaces in org.xml.sax.ext: Attributes2 , Locator2 , and EntityResolver2 . These all extend their respective core interfaces from org.xml.sax ( Attributes , Locator , and EntityResolver ), and class diagrams are shown for all three in Figure 4-7.


    Figure 4-7.  The Attributes2, EntityResolver2, and Locator2 interfaces

    These interfaces provide additional information for use in parsing, ranging from whether an attribute was specified in a DTD to the encoding of an XML document (pulled from the XML declaration). You can find out if your parser supports and uses these extensions via the getFeature() method:

      // Check for Attributes2 usag e
      featureURI = "http://xml.org/sax/features/use-attributes2";
      jTreeHandler.setUsingAttributes2(reader.getFeature(featureURI));

      // Check for Locator2 usage
      featureURI = "http://xml.org/sax/features/use-locator2";
      jTreeHandler.setUsingLocator2(reader.getFeature(featureURI));

    These and all other SAX-standard feature and property URIs are detailed in the Appendix.

    More Java Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Java and XML, Third Edition," published by...
     

    Buy this book now. This article is excerpted from chapter four of the book Java and XML, Third Edition, written by Brett McLaughlin and Justin Edelson (O'Reilly, 2006; ISBN: 059610149X). Check it out today at your favorite bookstore. Buy this book now.

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek