Name
ContentHandler
Synopsis
This interface is the key one for XML
parsing with the SAX API. An XMLReader
tells your
application about the content of the XML document it is parsing by
invoking the various methods of the ContentHandler
interface. In order to parse documents with SAX, you must implement
this interface to define methods that take whatever actions are
necessary when they are invoked by the parser. Because this interface
is so critical to the SAX API, the methods are explained individually
below:
-
setDocumentLocator( )
The parser usually calls this method (but is not required to do so) before calling any others to pass a
Locator
object to theContentHandler
.Locator
defines methods that return the current line and column number of the document being parsed, and if the parser supplies aLocator
object, it guarantees that its methods will return valid values during any otherContentHandler
invocations that follow. AContentHandler
can call the methods of this object when printing error messages, for example.-
startDocument( ), endDocument( )
The parser calls these methods once, at the beginning and end of parsing.
startDocument( )
is the first method called except for the optionalsetDocumentLocator( )
call, andendDocument( )
is always the last method call on aContentHandler
.-
startElement( ), endElement( )
The parser calls these methods for each start tag and end tag it encounters. Both are passed three arguments describing the name of the tag: if the parser is doing namespace ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.