Java Reference
In-Depth Information
parse(File aFile,
DefaultHandler handler)
Parses the document in the file specified by
aFile using handler as the object
containing the callback methods called by
the parser. This will throw an exception of
type IOException if an I/O error occurs
and of type
IllegalArgumentException if aFile
is null .
parse(String uri,
DefaultHandler handler)
Parses the document specified by uri using
handler as the object defining the callback
methods. This will throw an exception of
type SAXException if uri is null and an
exception of type IOException if an I/O
error occurs.
parse(InputStream input,
DefaultHandler handler)
Parses input as the source of the XML
with handler as the event handler. This
will throw an exception of type
IOException if an I/O error occurs, and
of type IllegalArgumentException if
input is null .
parse(InputStream input,
DefaultHandler handler,
String systemID)
Parses input as above, but uses systemID
to resolve any relative URIs.
parse(InputSource source,
DefaultHandler handler)
Parses the document specified by source
using handler as the object providing the
callback methods to be called by the parser.
The InputSource class is defined in the org.xml.sax package. It defines an object that wraps a
variety of sources for an XML document that you can use to pass a document reference to a parser. You
can create an InputSource object from an InputStream object, a Reader object encapsulating a
character stream, or a String specifying a URI - either a public name or a URL. If you specify the
document source as a URL, it must be fully qualified.
Implementing a SAX Handler
As we have already seen, the DefaultHandler class in the org.xml.sax.helpers package
provides a default do-nothing implementation of each of the callback methods a SAX parser may call
when parsing a document. These methods are declared in four interfaces that are implemented by the
DefaultHandler class:
The ContentHandler interface declares methods that will be called to identify the content
of a document to an application. You will usually want to implement all the methods defined
in this interface in your subclass of DefaultHandler .
Search WWH ::




Custom Search