Home arrow Java arrow Extension Interfaces and SAX
JAVA

Extension Interfaces and SAX


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.

Author Info:
By: O'Reilly Media
Rating: 3 stars3 stars3 stars3 stars3 stars / 6
July 19, 2007
TABLE OF CONTENTS:
  1. · Extension Interfaces and SAX
  2. · Extension Interfaces
  3. · XMLFilters continued
  4. · XMLWriter

print this article
SEARCH DEVARTICLES

Extension Interfaces and SAX
(Page 1 of 4 )

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.


blog comments powered by Disqus
JAVA ARTICLES

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- 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 ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials