How to edit an XML file

Source: Internet
Author: User
Tags character set

XML documents can contain foreign characters such as Norwegian or French (Chinese, of course!). This part still can't translate according to the original text, some of the following content is I wrote

In order for your parser to understand these characters, you must unify the character encoding criteria in the XML document.

--------------------------------------------------------------------------------

Windows 95/98 Notepad
Windows 95/98 Notepad cannot save files in a Unicode encoded format.

You can use Notepad to edit and save an XML document that contains foreign characters (for example, Norwegian or French or Chinese)

<?xml version= "1.0"?>
<note>
<from> small en </from>
<to> Xiao Lin </to>
<message> go to hotpot together at night </message>
</note>

But if you open the XML document edited with Notepad in your browser, an error will occur.

--------------------------------------------------------------------------------

Using encoding in Windows 95/98 Notepad
Windows 95/98 Notepad Editing an XML file must be set for encoding properties.

To avoid errors, you can add a encoding attribute to the XML document declaration that indicates the encoding type of the XML document, but do not use Unicode encoding.

The following encoding type does not cause an error, and the Chinese character is displayed correctly:

<?xml version= "1.0" encoding= "gb2312"?>

The following encoding type does not cause an error, and the Chinese character is displayed correctly:

<?xml version= "1.0" encoding= "GBK"?>

The following encoding type does not cause an error, and the kanji display is not normal (garbled):

<?xml version= "1.0" encoding= "windows-1252"?>

The following encoding type does not cause an error, and the kanji display is not normal (garbled):

<?xml version= "1.0" encoding= "Iso-8859-1"?>

The following encoding type does not cause an error, and the Chinese character is displayed correctly:

<?xml version= "1.0" encoding= "UTF-8"?>

The following encoding type causes an error:

<?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 the Unicode character set. If you use Win2000 Notepad to save the XML document in Unicode encoding format (note that there is no encoded information in the XML declaration):

<?xml version= "1.0"?>
<note><from> small en </from><to> Xiao Lin </to><message> go to hotpot together at night </message></note >
--------------------------------------------------------------------------------

Windows 2000 Notepad encoding
Windows 2000 Notepad can also save files in the "UTF-16" encoding format.

If you declare an encoded attribute in an XML document and save the file in Unicode format, an error can 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 document; Note_encode_utf16_u.xml will appear normal in ie5.0+, and errors will occur in Netscape Netscape 6.2 browser.

<?xml version= "1.0" encoding= "UTF-16"?>

--------------------------------------------------------------------------------

Error message
When browsing an XML document with a IE5.0 or later version, you may encounter two different coding errors:

An illegal character was found in the text contents (an invalid character is found in text content).

If your XML document does not match the encoding format of your XML document, it can cause errors to occur. Typically, an XML document contains some "non-English" characters, and a single-byte-encoded editor is used, and the XML document's encoding format is not set in the declaration of an XML document.

Converting from the current encoding format to another encoding format is not supported (switch from encoding to specified encoding not supported).

If the XML document is saved in unicode/utf-16 encoding format, the XML document is formatted with a 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. However, in the declaration of an XML document, the encoding format is set to some unicode/utf-16 encoding, both of which can cause errors to occur.

--------------------------------------------------------------------------------

Conclusion
Conclusion: Set the encoding format of the document in the Declaration of the XML document before saving the XML document, some of my suggestions for avoiding errors:

Use an editor that supports Unicode encoding format.
Make sure you know you're using that coded format.
Use attribute declarations in XML documents to set the encoding format.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.