I have a basically question about XML in Android. This line that is shown at the top of XML files <?xml version="1.0" encoding="utf-8"?>
is changeable? I mean we can use for example utf-16 or another version of xml in our codes?

- 3,226
- 5
- 16
- 43
-
Does this answer your question? [Meaning of - ](https://stackoverflow.com/questions/13743250/meaning-of-xml-version-1-0-encoding-utf-8) – Randall Arms Apr 06 '20 at 06:49
-
No @Randall Arms, I know what is that line, but I want to know it is changeable or not? – MMG Apr 06 '20 at 06:52
-
Did you read the whole highest-voted answer linked? The final sentence, "In most cases (for English speakers anyway), version 1.0 is sufficient," implies that there are instances in which version 1.0 is not the chosen option. Also, the answerer writes, "you [may] need a different encoding as 128 characters is not enough to fit all the characters in. Some encodings offer one byte (256 characters) or up to six bytes," which implies there are times when the utf-8 encoding is not used. – Randall Arms Apr 06 '20 at 06:56
-
OK, when do we use utf-16? Is there any code with another version of xml? @Randall Arms – MMG Apr 06 '20 at 07:01
1 Answers
No, there are instances in which the XML encoding and version could or should be different. Different versions of XML are, as expected, different, while different encoding will allow for characters not included in traditional "utf-8" encoding.
EDIT: Re: "Thanks for your answer, I want example for it" & "OK, when do we use utf-16? Is there any code with another version of xml?"
UTF-16 doesn't have much use, as I understand; it is mostly just an old system used for backwards compatibility or for a code that maximizes efficiency with 16-bit over 8-bit. You might use UTF-32 as (from Wikipedia) "the Unicode code points are directly indexed."
From another post on StackOverflow regarding XML versions, "You would only need to use version 1.1 if you are using certain non-ASCII characters in identifiers, EBCDIC line ending characters, or control characters (character codes 1 - 31)."

- 407
- 1
- 5
- 22
-
-
@MohammadMoeinGolchin Okay, I edited my answer to respond to your added questions. – Randall Arms Apr 06 '20 at 07:18
-
Thanks for the referenced link, I didn't add my questions. I was just thinking that why we use always this line at the top of XMLs. I want to get example code that this version of XML and this unicode type is not useful and we should use another one. Do you have any code? – MMG Apr 07 '20 at 04:32