Name
InputSource
Synopsis
This simple class describes a source of input
for an XMLReader
. An
InputSource
object can be passed to the
parse( )
method of XMLReader
,
and is also the return value of the
EntityResolver.resolveEntity( )
method.
Create an InputSource( )
with one of the
constructor methods, specifying the system identifier (a URL) of the
file to be parsed, or specifying a byte or character stream that the
parser should read the document from. In addition to calling the
constructor, you may also want to call setSystemId(
)
to specify and/or setPublicId( )
to
provide identifiers for the document being parsed. Having a filename
or URL is useful if an error arises, and your
ErrorHandler
object needs to print an error
message, for example. If you specify the document to parse as a URL
or as a byte stream, you can also call setEncoding(
)
to specify the character encoding of the document. The
parser will use this encoding value if you supply it, but XML
documents are supposed to describe their own encoding in the
<?xml?>
declaration, so the parser ought to
be able to determine the encoding of the document even if you do not
call setEncoding( )
.
This class allows you to specify more than one input source. The
XMLReader
will first call
getCharacterStream( )
and use the returned
Reader
if there is one. If that method returns
false
, then it calls getByteStream(
)
and uses the InputStream
it returns.
Finally, if no character or byte stream is found, then the parser
will call getSystemId( ...
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.