[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SAX InputSource and character streams
- From: Mike Brown <mike@skew.org>
- To: xml-dev@lists.xml.org
- Date: Wed, 21 Feb 2001 18:14:03 -0700 (MST)
Rick Jelliffe wrote:
> From: Rob Lugt <roblugt@elcel.com>
> >... So, in
> >this case, by deciding to pass the SAX Parser a character stream, the
> >application has taken on part of the responsibility of an XML processor -
> >namely the responsibility of dealing with any encoding issues, thereby
> >relieving the SAX processor of any need, indeed any right, to have an
> >opinion on how the encoding is performed.
>
> For encoding, the general rule is that (reliable) information provided by a
> higher-level protocol has preference over the header.
> [...]
> So a processor needs some mechanism to over-ride auto-detection.
I think you're talking about something else? I'm really just asking about
the SAX InputSource. Quoting from the SAX API:
"The SAX parser will use the InputSource object to determine how to read
XML input. If there is a character stream available, the parser will read
that stream directly; if not, the parser will use a byte stream, if
available; if neither a character stream nor a byte stream is available,
the parser will attempt to open a URI connection to the resource
identified by the system identifier."
My question was, when supplying a character stream to the parser, is it
reasonable to expect that the parser will not complain if the encoding
declaration says the encoding is (was) something the parser does not
support?
And should I be concerned that there is an encoding declaration which says
the document has encoding foo, when in fact it doesn't, because it is at
that point being dealt with as relatively abstract characters and thus is
not encoded at all?
Rob Lugt says my gut feeling is right, but David Brownell seems to be
saying the ambiguity in the XML & SAX specs means I shouldn't assume
anything, and that it would be perfectly reasonable for a parser to
complain when fed an InputSource constructed like this:
new InputSource(
new StringReader( "<?xml version=\"1.0\" encoding=\"some-unsupported-encoding\"?><bar/>" )
);
It's this statement that really worries me: "In the absence of information
provided by an external transport protocol (e.g. HTTP or MIME), it is an
error for an entity including an encoding declaration to be presented to
the XML processor in an encoding other than that named in the declaration,
or for an entity which begins with neither a Byte Order Mark nor an
encoding declaration to use an encoding other than UTF-8."
XML seems to assume that every parsed entity that a processor encounters
consists of encoded characters (bytes, essentially), whereas in practice
we obviously have parsers that accept the entities as characters.
- Mike
____________________________________________________________________
Mike J. Brown, software engineer at My XML/XSL resources:
webb.net in Denver, Colorado, USA http://skew.org/xml/