InputSource
The application can use instances of the InputSource
class, provided in the xml.sax.xmlreader
module, as return values
from the resolveEntity
method of
the EntityResolver
interface, or as
parameters to the parse
convenience
function or XMLReader
method. There
should not normally be a reason to use an alternate implementation of
this class, but it is allowed. When the application prepares an
InputSource
to provide to the
parser, it should use the various set
methods to configure the object with as
much information as it has about the input source.
When the parser receives the InputSource
instance, it first attempts to
use the character stream if it is available; otherwise it uses the
byte stream. If neither of those is available, it uses the system
identifier and attempts to open a byte stream itself.
getByteStream( )
Returns the byte stream associated with this input source. This is a stream that returns raw bytes from the input source rather than decoded Unicode characters.
getCharacterStream(
)
Returns the character stream associated with this input source. A character stream provides the parser with decoded Unicode characters rather than raw bytes.
getEncoding( )
Returns the encoding of the byte stream if known.
If it is not known, return None
. If the encoding is not known,
the parser applies the rules for auto-detection of the encoding
based on the leading bytes of the input stream.
getPublicId( )
Returns the public identifier of the input source,
or None
if there isn’t one or
if it isn’t known.
getSystemId( )
Returns the system identifier of the input source,
or None
if there isn’t one or
if it isn’t known. The only time this should ever return
None
for a fully initialized
input source is if the source is being used to provide the
document entity and the input source is provided by the user
instead of a URL or filename.
setByteStream(
stream
)
Sets the byte stream of the input source. This should be used if the bytes of the entity can be referenced more efficiently than the parser would be able to do based on the system identifier. This is appropriate when loading the document from a cache rather than loading it across the network.
setCharacterStream(
stream
)
Sets the character stream for the input source. This should be used if the source can provide Unicode characters directly.
setEncoding(
encoding
)
Sets the encoding of the byte stream to
encoding
. This may be known if the
resource is being loaded using a protocol that provides this
information directly. HTTP, for instance, can include
information about the character encoding as the charset
parameter to the Content-Type
header in the
response.
setPublicId(
id
)
setSystemId(
id
)
3.133.142.2