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
Locatorobject to theContentHandler.Locatordefines methods that return the current line and column number of the document being parsed, and if the parser supplies aLocatorobject, it guarantees that its methods will return valid values during any otherContentHandlerinvocations that follow. AContentHandlercan 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access