


It was designed for backward compatibility with ASCII: the first 128 characters of Unicode, which correspond one-to-one with ASCII, are encoded using a single byte with the same binary value as ASCII, so that valid ASCII text is valid UTF-8-encoded Unicode as well. Code points with lower numerical values, which tend to occur more frequently, are encoded using fewer bytes. UTF-8 is capable of encoding all 1,112,064 valid character code points in Unicode using one to four one- byte (8-bit) code units. Defined by the Unicode Standard, the name is derived from Unicode (or Universal Coded Character Set) Transformation Format – 8-bit.

only if parsing the document as UTF-8 fails.UTF-8 is a variable-width character encoding used for electronic communication. UTF-8 is now the de facto default encoding for the Internet, so any text file whose encoding is unknown should be parsed as UTF-8 first, falling back to "legacy" encodings like Windows-1252, Latin-1, etc. But it should really be avoided as much as possible. However, some broken tools (Microsoft, I'm looking at you since you're the ones who made most of them) will misinterpret text if it doesn't contain a BOM, so adding a BOM to UTF-8 encoded text is sometimes necessary. Personal rant: It's a very good idea to leave BOMs out of your UTF-8 encoded text. It didn't add a BOM, but the source that you copied and pasted your XML from contained a BOM, so you got one in your output anyway because you had one in your input. You were using 8Encoding(false) correctly. This is why I often refer to the BOM as a BOM(b) - because it sits there silently, hidden, waiting to blow up on you when you least expect it. You can also copy and paste from the " < that I put in this answer: I copied those characters from your question, so they contain the invisible BOM immediately before the space character. U+FEFF : ZERO WIDTH NO-BREAK SPACE (alias BYTE ORDER MARK )

For example, pasting that text into gave me the following result: U+0022 : QUOTATION MARK To prove it, select the text " < from your XML encoding (the opening double-quote, the space following it, and the opening < character) and paste that into any tool that tells you Unicode codepoints. What appears to be a space at the start of your XML declaration is actually a BOM followed by a space. The reason you were seeing a BOM in the output is because there's a BOM in your input. This question is more than two years old, but I've found the answer.
