XML documents may contain foreign characters, like Norwegian ???, or French ???
XML文檔中可以使用外來字元,比如挪威語或法語
To let your XML parser understand these characters, you should save your XML documents as Unicode.
如要使你的XML解析器能夠讀懂這些字元,你就應該將XML文檔儲存為統一代碼(Unicode)
Windows 2000 寫字板
Windows 2000 Notepad can save files as Unicode.
使用WIN2000的寫字板就可以將檔案儲存為Unicode
Save the XML file below as Unicode (note that the document does not contain any encoding attribute):
將以下XML檔案儲存為Unicode編碼(可以注意下問檔沒有包含任何編碼屬性):
<?xml version="1.0"?> <note> <from>Jani</from> <to>Tove</to> <message>Norwegian: 驤? French: 覘?lt;/message> </note> |
The file above, note_encode_none_u.xml will NOT generate an error in IE 5+, Firefox, or Opera, but it WILL generate an error in Netscape 6.2.
上面這個檔案在IE5+,Firefox, 或Opera中不會產生任何錯誤,但它在Netscape 6.2裡會有一個錯誤。
Windows 2000 寫字板附帶編碼
Windows 2000 Notepad files saved as Unicode use "UTF-16" encoding.
將檔案儲存為"UTF-16"編碼格式
If you add an encoding attribute to XML files saved as Unicode, windows encoding values will generate an error.
如果你給XML檔案加上編碼屬性,wendows的編碼值會產生錯誤。
The following encoding (open it), will NOT give an error message:
使用下面的編碼,不會給出任何錯誤。
<?xml version="1.0" encoding="windows-1252"?> |
The following encoding (open it), will NOT give an error message:
使用下面的編碼,不會產生任何錯誤
<?xml version="1.0" encoding="ISO-8859-1"?> |
The following encoding (open it), will NOT give an error message:
使用下面的編碼,不會產生任何錯誤
<?xml version="1.0" encoding="UTF-8"?> |
The following encoding (open it), will NOT generate an error in IE 5+, Firefox, or Opera, but it WILL generate an error in Netscape 6.2.
使用下面的編碼在IE 5+, Firefox, 或 Opera 中不會產生任何錯誤,但在Netscape 6.2裡會有錯誤
<?xml version="1.0" encoding="UTF-16"?> |
錯誤資訊
If you try to load an XML document into Internet Explorer, you can get two different errors indicating encoding problems:
如果你試著 把XML文檔載入Internet Explorer,你會得到關於編碼問題的兩個不同的錯誤資訊
An invalid character was found in text content.
在常值內容中發現一個無效字元
You will get this error message if a character in the XML document does not match the encoding attribute. Normally you will get this error message if your XML document contains "foreign" characters, and the file was saved with a single-byte encoding editor like Notepad, and no encoding attribute was specified.
如果XML文檔中有一個字元與編碼屬性不匹配,你就會得到這個錯誤資訊。一般來講,如果你的XML的文檔包含外文字元,或檔案是以記事本單位元組編輯器來儲存的,或編碼屬性沒有被指定的,你就會得到這個錯誤資訊。
Switch from current encoding to specified encoding not supported.
從現在的編碼切換到非支援的指定編碼
You will get this error message if your file was saved as Unicode/UTF-16 but the encoding attribute specified a single-byte encoding like Windows-1252, ISO-8859-1 or UTF-8. You can also get this error message if your document was saved with single-byte encoding, but the encoding attribute specified a double-byte encoding like UTF-16.
如果編碼屬性指定為像Windows-1252, ISO-8859-1 或 UTF-8的單位元組編碼,而你的檔案卻是以Unicode/UTF-16儲存的,你就會得到這個出錯資訊
結論
The conclusion is that the encoding attribute has to specify the encoding used when the document was saved. My best advice to avoid errors is:
結論就是在檔案儲存時,編碼屬性應指定被用的編碼,我對避免錯誤的最好建議是:
- Use an editor that supports encoding
• 使用支援編碼的編輯器
- Make sure you know what encoding it uses
• 你得弄清楚在使用的是什麼編碼
- Use the same encoding attribute in your XML documents
• 在你的XML文檔中使用相同的編碼屬性