[XML] garbled solution for UTF8 and GB2312 encoding conversion

Source: Internet
Author: User
After reviewing the information, you must generate an XML file and use GB2312 encoding for the XML file. many websites use UTF8 encoding for the collected news websites, in this way, an XML file must be generated after garbled information is reviewed during the conversion process, and the XML file must adopt GB2312 encoding, because the collected news websites, many websites use UTF-8 encoding, which leads to garbled characters during conversion.

A small project has been developed recently. if you encounter such problems, record them as a summary.
This project is divided into two parts: news data collection, audit of collected information, and XML file generated at last.
After the collected data is edited by the user, you need to export an ACCESS file and import the file to the information review system. The field type for storing news information in the ACCESS library is ntext, and the review system Library corresponds to a varchar (max) field. after the import, it is found that some blank characters may contain garbled characters, displayed as question mark (?), In fact, after subsequent tests, this is not a blank (space) character, but a special character, what should I do? After several tests, we found that the varchar (max) type should be changed to the nvarchar (max) type, so that the imported data will not have such problems.
However, during subsequent testing, you will find that the imported collection information is changed (pass. after the net program editing function), this information in the database has encountered garbled characters. after research, it is found that the insert statement will not be written in this way, such as insert into table name (news) values (n' "+ updated value +" "), Why N? Go to Baidu to understand.
At this point, my heart was comforted, but the problems that followed were depressing ......
After reviewing the information, you must generate an XML file and use GB2312 encoding for the XML file. many websites use UTF8 encoding for the collected news websites, in this case, garbled characters (or the special character "blank") occur during the conversion process. what should I do? We can convert UTF8 into GB2312 on the Internet, but we found that the problem still cannot be solved. this morning, to solve this problem, we still have no way to solve it. when we are depressed, I suddenly thought of using the debugging function of VS to see what this special character is. Finally, I read this field value from the database and convert it into a character array, content. toCharArray (); one by one. The character that causes garbled characters is the space in the quotation marks. this is not a space, but a special character that cannot be recognized in GB2312, at this point, I suddenly thought, can I directly replace the value of this character with a space? Action immediately. the garbled problem was fixed. This is a waste of half a day.
Note that this value must be used for debugging (because this is the special character that causes garbled characters), even if it is pasted in the form during debugging.

The code is as follows:

content = content.Replace(" ", " ");

The above is the detailed content of the garbled solution for UTF-8 and GB2312 encoding conversion in XML. For more information, see other related articles in the first PHP community!

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.