Home arrow Java arrow Page 2 - Entities, Handlers and SAX
JAVA

Entities, Handlers and SAX


Picking up from where we left off yesterday, we'll take a look at entities and handlers in 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: 5 stars5 stars5 stars5 stars5 stars / 8
July 12, 2007
TABLE OF CONTENTS:
  1. · Entities, Handlers and SAX
  2. · Notations and Unparsed Entities
  3. · The DefaultHandler Class
  4. · LexicalHandler

print this article
SEARCH DEVARTICLES

Entities, Handlers and SAX - Notations and Unparsed Entities
(Page 2 of 4 )

After a rather extensive look at EntityResolver, Iím going to cruise through DTDHandler (also in org.xml.sax ). In almost nine years of extensive SAX and XML programming, Iíve used this interface only onceóin writing JDOM (covered in Chapter 9)óand even then, it was a rather obscure case. Still, if you work with unparsed entities often, are into parser internals, or just want to get into every nook and cranny of the SAX API, then you need to know about DTDHandler . The interface is shown in all its simplicity in Figure 4-4.


Figure 4-4.  This handler is concerned with the declartion of certain XML types, rather than the actual content of those entities (if and when they are resolved)

The DTDHandler interface allows you to receive notification when a reader encounters an unparsed entity or notation declaration. Of course, both of these events occur in DTDs, not XML documents, which is why this is called DTDHandler . The two methods listed in Figure 4-4 do exactly what you would expect. The first reports a notation declaration, including its name, public ID, and system ID. Remember the NOTATION structure in DTDs? (Flip back to Chapter 2 if youíre unclear.)

  <!NOTATION jpeg SYSTEM "images/jpeg">

The second method provides information about an unparsed entity declaration, which looks as follows:

  <!ENTITY stars_logo SYSTEM "http://www.nhl.com/img/team/dal38.gif"  
                     NDATA jpeg>

In both cases, you can take action at these occurrences if you create an implementa tion of DTDHandler and register it with your reader through the XMLReader ís setDTDHandler() method. This is generally useful when writing low-level applications that must either reproduce XML content (such as an XML editor), or when you want to build up some Java representation of a DTDís constraints (such as in a data binding implementation). In most other situations, it isnít something you will need very often.


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