ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: XML :: XML×Ö·û±àÂë

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

XML
XML DHTMLÐÐΪ
XML Ïà¹Ø¼¼Êõ
XML ±à¼­Æ÷
XML ÕªÒª
XML ʵÀý
XML×Ö·û±àÂë
xml ÎĵµÊ÷
IEºÍ»ðºü¶ÁÈ¡XML·..

XML×Ö·û±àÂë


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ÐÞ¸Ä:2007-08-16 ä¯ÀÀ:3823 :: ::

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.
WIN2000¼Çʱ¾¿ÉÒÔʹÓÃ"UTF-16"±àÂë¸ñʽ½«ÎļþÒԓͳһ×Ö·û±àÂ루Unicode£©”µÄÐÎʽ±£´æ¡£

If you add an encoding attribute to XML files saved as Unicode, windows encoding values will generate an error.
Èç¹ûÄã¸øÒԓͳһ×Ö·û±àÂ루Unicode£©”µÄÐÎʽ±£´æµÄXMLÎļþ¼ÓÉÏÒ»¸ö±àÂëÊôÐÔ£¬ÄÇô£¬windowsµÄ±àÂëÖµ»á²úÉú´íÎó¡£

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.
Èç¹ûÄãµÄÎļþÊÇÒÔ“ Unicode/UTF-16 ” À´±£´æµÄ£¬µ«ÊÇ£¬ËüÃǵıàÂëÊôÐÔÖ¸¶¨ÎªÖîÈ磺“Windows-1252”¡¢“ISO-8859-1”»ò“UTF-8”ÕâÑùµÄµ¥×Ö½Ú±àÂ룬ÄÇô£¬Äã»áÊÕµ½´íÎóÐÅÏ¢£»Èç¹ûÄãµÄÎĵµÊ¹Óõ¥×Ö½Ú±àÂëÐÎʽ±£´æ£¬µ«ÊÇ£¬±àÂëÊôÐÔÖ¸¶¨ÎªÖîÈ磺“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ÎĵµÖÐʹÓÃÏàͬµÄ±àÂëÊôÐÔ

ÆÀÂÛ (0) All