[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: SAX InputSource and character streams
Rick Jelliffe wrote: > From: Rob Lugt <roblugt@e...> > >... 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/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|