Earlier quoted context omitted.
By default XML is either UTF-8 or 16, any other encoding has to be identified either through metadata or an explicit declaration in the document itself. If you are guessing it is because someone failed to properly store or transmit the document.
By "through metadata", you mean with some external separate mechanism unrelated to the XML spec? That's exactly the flaw of what's supposed to be a universal and general document representation. Both UTF-8 or UTF-16 are supported, yes, but that doesn't solve the problem because XML parsers have to deal with other encodings. A document that initially looks like UTF-8 could be almost any of literally hundreds of encodi…
The code generating the xml text may not be aware of the final encoding used to store/transmit it and a library writing text to an encoded stream might not be aware that the text it is sending contains xml. So I would say allowing xml to be parsed using an externally specified encoding makes at least some sense.
> A document that initially looks like UTF-8 could be almost any of literally hundreds of encodings including all the common ISO 8859 encodings
Your own link shows that those "hundreds of encodings" are all based on ASCII, which is enough to get the concrete encoding from the declaration.
> and then switch to a "parsing" phase after rewinding to the start of the document.
So one call to fseek(stream, 0, SEEK_SET)?