Home > Article > Backend Development > Detailed introduction on how to edit xml files
XMLThe document can contain foreign characters such as Norwegian or French (Chinese is also acceptable! This part still cannot be translated according to the original text, some of the following content is written by myself)
For For your parser to understand these characters, you must adopt a consistent character encoding standard in the XML document.
-------------------------------------------------- ------------------------------------
Windows 95/98 Notepad
Windows 95/98 Notepad cannot save files in Unicode encoding format.
You can use Notepad to edit and save XML documents containing foreign characters (for example: Norwegian or French or Chinese)
<?xml version="1.0"?> <note> <from>小奀</from> <to>小林</to> <message>晚上一起去火锅呀</message> </note>
But if you open this with a browser and edited it with Notepad XML document, an error will occur.
-------------------------------------------------- ------------------------------------
in Windows 95/98 Notepad Using encoding
Windows 95/98 Notepad to edit XML files must set the encodingattribute.
In order to avoid errors, you can add an encoding attribute to the XML document declaration to indicate the encoding type of this XML document, but do not use Unicode encoding.
The following encoding type will not cause errors, and Chinese characters will be displayed normally:
<?xml version="1.0" encoding="gb2312"?>
The following encoding types will not cause errors, and Chinese characters will be displayed normally:
<?xml version="1.0" encoding="gbk"?>
The following encoding type will not cause errors, and Chinese characters will not be displayed normally (garbled characters):
<?xml version="1.0" encoding="windows-1252"?>
The following encoding types will not cause errors, and Chinese characters will be displayed abnormally (garbled characters) :
<?xml version="1.0" encoding="ISO-8859-1"?>
The following encoding types will not cause errors, and Chinese characters are displayed normally:
<?xml version="1.0" encoding="UTF-8"?>
The following encoding types will cause errors:
<?xml version="1.0" encoding="UTF-16"?>
--------------------------------------------- ----------------------------------
Using Windows 2000 Notepad
Windows 2000 Notepad can save files in Unicode encoding format.
Notepad for Windows 2000 supports Unicodecharacter set. If you use Win2000 Notepad to save the XML document in Unicode encoding format (please note that there is no encoding information in the XML declaration):
<?xml version="1.0"?> <note><from>小奀</from><to>小林</to><message>晚上一起去火锅呀</message></note>
---------------- -------------------------------------------------- --------------
Windows 2000 Notepad Encoding
Windows 2000 Notepad can also save files in "UTF-16" encoding format.
If you declare the encoding attribute in the XML document and save the file in Unicode encoding format, an error may occur.
The following code will cause an error:
<?xml version="1.0" encoding="windows-1252"?>
The following code will cause an error:
<?xml version="1.0" encoding="ISO-8859-1"?>
The following code will cause an error:
<?xml version="1.0" encoding="UTF-8"?>
The following file; note_encode_utf16_u.xml, will display normally in IE5.0+, but will cause an error in Netscape 6.2 browser.
<?xml version="1.0" encoding="UTF-16"?>
---------------------------------------- -------------------------------------
Error message
When using IE5.0 or higher to browse XML documents, you may encounter two different encoding errors:
An invalid character was found in the text content (An invalid character was found in text content).
If your XML document does not match the encoding format of your XML document, an error may occur. Usually, the XML document contains some "non-English" characters and uses single-byte encoding Editor, and the encoding format of the XML document is not set in the declaration of the XML document.
Conversion from the current encoding format to another encoding format is not supported (Switch from current encoding to specified encoding not supported ).
If the XML document is saved in Unicode/UTF-16 encoding format, but the declaration of the XML document sets the encoding format to be some single-byte encoding (such as Windows-1252, ISO-8859-1 or UTF -8); or the XML document is saved in a single-byte encoding format, but the declaration of the XML document sets the encoding format to be some Unicode/UTF-16 encoding form. Both situations will cause errors.
-------------------------------------------------- ------------------------------------
Conclusion
Conclusion: After saving Before setting the encoding format of the document in the declaration of the XML document, some of my suggestions to avoid errors:
Use an editor that supports Unicode encoding format.
Make sure you know which encoding format you are using.
Use attribute declarations to set the encoding format in XML documents.
The above is the detailed content of Detailed introduction on how to edit xml files. For more information, please follow other related articles on the PHP Chinese website!