How to edit an xml file

Source: Internet
Author: User

How to edit an xml file

XML documents can contain foreign characters, such as Norwegian or French (Chinese can, of course! This part still cannot be translated as the original text, and some of the following content is written by myself)

To enable your parser to understand these characters, you must unify the character encoding standards 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> small shard </from>
<To> Kobayashi </to>
<Message> go to the hot pot together at night </message>
</Note>

However, if you open the XML document edited in notepad in a browser, an error will occur.

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

Use encoding in Windows 95/98 notepad
For Windows 95/98 notepad, encoding attributes must be set for editing XML files.

To avoid errors, you can add an encoding attribute in the XML Document declaration to indicate the encoding type of this XML document, but do not use Unicode encoding.

The following encoding type does not cause errors and the Chinese characters are displayed normally:

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

The following encoding type does not cause errors and the Chinese characters are displayed normally:

<? Xml version = "1.0" encoding = "gbk"?>

The following encoding types do not cause errors, and Chinese characters are not displayed properly (garbled ):

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

The following encoding types do not cause errors, and Chinese characters are not displayed properly (garbled ):

<? Xml version = "1.0" encoding = "ISO-8859-1"?>

The following encoding type does not cause errors and the Chinese characters are displayed normally:

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

The following encoding type may cause errors ,:

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

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

Use Windows 2000 notepad
Windows 2000 notepad can save files in Unicode encoding format.

Windows 2000 notepad supports the Unicode Character Set. If you use Win2000 notepad to save the XML document in Unicode encoding format (note that there is no encoding information in the XML declaration ):

<? Xml version = "1.0"?>
<Note> <from> Xiao Yu </from> <to> Xiao Lin </to> <message> go to the hot pot together at night </message> </note>
--------------------------------------------------------------------------------

Windows 2000 notepad Encoding
Windows 2000 notepad also saves 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 errors:

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

The following code will cause errors:

<? Xml version = "1.0" encoding = "ISO-8859-1"?>

The following code will cause errors:

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

The following file: note_encode_utf16_u.xml will be displayed normally in IE5.0 +, and an error will appear in Netscape 6.2 browser.

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

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

Error Message
When you use IE5.0 or a later version to browse XML documents, you may encounter two different encoding errors:

An invalid character was found in text content is found in the text ).

If your XML document does not match the encoding format of your XML document, an error may occur. Generally, an XML document contains "non-English" characters, uses a single-byte encoding editor, and does not set the encoding format of an XML document in the declaration of an XML document.

Switch from current encoding to specified encoding not supported is not supported ).

If the XML document is saved in Unicode/UTF-16 encoding format, but the Declaration in the XML document sets the encoding format to 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 some Unicode/UTF-16 encoding format, both of which will cause errors.

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

Conclusion
Conclusion: Before saving the XML document, set the document encoding format in the declaration of the XML document. Some of my suggestions on avoiding errors:

Use an editor that supports Unicode encoding format.
Make sure you know that you are using that encoding format.
In the XML document, use the attribute declaration to set the encoding format.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.