Java Reference
In-Depth Information
The
EntityResolver
interface declares one method,
resolveEntity()
, that is called by
a parser to pass a public and/or system ID to your application to allow external entities in the
document to be resolved.
❑
The
DTDHandler
interface declares two methods that will be called to notify your application
of DTD-related events.
❑
The
ErrorHandler
interface defines three methods that will be called when the parser has
identified an error of some kind in the document.
❑
All four interfaces are defined in the
org.xml.sax
package. Of course you can define a handler class that
implements these interfaces, but you will probably find it easier to extend the
DefaultHandler
class.
The basic methods that you must implement to deal with parsing events related to document content
are those declared by the
ContentHandler
interface so let's concentrate on those first. All the
methods have a
void
return type, and they are as follows
startDocument()
Called when the start of a document is
recognized.
endDocument()
Called when the end of a document is
recognized.
startElement(String uri,
String localName,
Called when the start of an element is
recognized. Up to three names may be
provided for the element:
String qName,
Attributes attr)
uri
is the namespace URI for the element
name. This will be an empty string if there is
no uri or if namespace processing is not
being done.
localName
is the unqualified local name
for the element. This will be an empty string
if namespace processing is not being done.
In this case the element name is reported via
the
qName
parameter.
qName
is the qualified name for the element.
This will be just the name if the parser is not
namespace aware. (A colon, if it appears, is
then just an ordinary character.)
The
attr
reference encapsulates the
attributes for the element that have explicit
values.