See the XML 1.0 specification, section "F Autodetection of Character Encodings (Non-Normative)":
The XML encoding declaration functions as an internal label on each entity, indicating which character encoding is in use. Before an XML processor can read the internal label, however, it apparently has to know what character encoding is in use—which is what the internal label is trying to indicate. In the general case, this is a hopeless situation. It is not entirely hopeless in XML, however, because XML limits the general case in two ways: each implementation is assumed to support only a finite set of character encodings, and the XML encoding declaration is restricted in position and content in order to make it feasible to autodetect the character encoding in use in each entity in normal cases.
And:
Because each XML entity not accompanied by external encoding information and not in UTF-8 or UTF-16 encoding must begin with an XML encoding declaration, in which the first characters must be <?xml, any conforming processor can detect, after two to four octets of input, which of the following cases apply.
And:
Because the contents of the encoding declaration are restricted to characters from the ASCII repertoire (however encoded), a processor can reliably read the entire encoding declaration as soon as it has detected which family of encodings is in use.
So, whichever encoding is used, a conformant parser should be able to auto-detect the encoding used for the document and parse the actual value of the "encoding" attribute.
After reading this, the parser might have to reset the stream and use another reader to properly read the entire document.