How to release XML garbled characters generated by ASP

Source: Internet
Author: User

<! -- # Include file = "../INC/Conn. asp" -->
<%
Call opendata (1)
Set rs = server. Createobject ("ADODB. recordset ")
Xmlfile = server. mappath ("content. xml ")
Set FSO = Createobject ("scripting. FileSystemObject ")
Set myfile = FSO. createtextfile (xmlfile, true,-1)
Myfile. writeline ("<? XML version = "" 1.0 "" encoding = "" UTF-8 "" standalone = "" yes ""?> ")
Myfile. writeline ("<content name =" "news" "> ")
Rs. Open "select * From detail where classid = 268 order by updatetime DESC", Conn, 1, 1
If not Rs. EOF then
Do while not Rs. EOF
Myfile. writeline ("<Article thumb =" "News/thumb4.jpg" "Large =" "News/large4.jpg" "> ")
Myfile. writeline ("Myfile. writeline ("<date> 2010/05/01 </date> ")
Myfile. writeline ("<copy_intro> <! [CDATA [bamboo cube, fresh from the depths of bamboo forests, the call for low carbon and environmental protection in the age, and the concept of healthy and fashionable modern life]> </Copy_intro> ")
Myfile. writeline ("<copy_full> <! [CDATA [bamboo cube, fresh from the depths of bamboo forests, the call for low carbon and environmental protection in the age, and the concept of healthy and fashionable modern life. <Br> bamboo cube is a bamboo Art Museum mainly used for bamboo charcoal, bamboo wood, bamboo furniture, and bamboo crafts. It cooperates with the most powerful manufacturers to provide first-hand supply, it provides low-carbon and environmentally friendly bamboo products for people pursuing modern urban lifestyle. <Br> think of bamboo, and think of the green. Bamboo, from bamboo, bamboo to bamboo, bamboo floor, bamboo, and bamboo contribute in obscurity with its humble character. Its unique quality, characteristics, and development prospects are limitless. <Br> come to bamboo cube and feel the magic of bamboo!]> </Copy_full> ")
Myfile. writeline ("<copy_pic> <! [CDATA [bamboo cube]> </copy_pic> ")
Myfile. writeline ("</Article> ")
Rs. movenext
Loop
End if
Rs. Close
Myfile. writeline ("</content> ")
Myfile. Close
%>

 

 

I recently studied ASP to generate xml files and found that if the generated files contain Chinese characters, the XML files are garbled. I found it on the Internet and set all the pages and XML to uniform encoding, but they did not solve the problem.

Cause:Later I found that FSO was the problem: FSO does not support UTF-8.

Solution:The third parameter set myfile = FSO. createtextfile (xmlfile, true,-1) is very important-1 is the true value of Boolean;

 

Expansion:

The following describes the parameters of createtextfile:
Object. createtextfile (filename [, overwrite [, Unicode])
Parameters
Object
Required. The name of the FileSystemObject or folder object.
Filename
Required. Specifies the string expression of the file to be created.
Overwrite
Optional. Boolean value, indicating whether to overwrite existing files. If the file can be overwritten, the value is true; otherwise, the value is false. If not, existing files cannot be overwritten.
Unicode
Optional. Boolean value, indicating whether the file is created in Unicode or ASCII format. If the file is created as a Unicode file, the value is true. If the file is created as an ASCII file, the value is false. If this parameter is ignored, it is assumed to be an ASCII file.

 

Sample Code:

<%
Xmlfile = server. mappath ("media. xml ")
Set FSO = Createobject ("scripting. FileSystemObject ")
Set myfile = FSO. createtextfile (xmlfile, true,-1)
Myfile. writeline ("<? XML version = "" 1.0 "" encoding = "" UTF "&"-8 ""?> ")
Myfile. writeline ("<settings autorotate =" "1" "autorotatespeed =" "4" "usesubtitle =" "0" "usetooltip =" "1" "usesecondcaption =" "1 "" spanx = "" 400 "" spany = "" 40 "" centerx = "" 500 "" centery = "300" "distancevalue =" "0" "perspectiveratio =" "0.5 """ minimumscale = "". 1 "" turningspeed = "4" "rotationkind =" "1" "usefocalblur =" 1 "" focalblurvalue = "". 6 "" usemotionblur = "" 1 "" motionblurvalue = "". 25 "" usefadeonmouseover = "1" "mouseoveralphavalue = "". 5 "" usereflection = "" 1 "" reflectionalphavalue = "". 5 """)
Myfile. writeline ("/> ")
%>

<%
Myfile. writeline ("<photos> ")
%>
<%

Myfile. writeline ("<photo imageurl =" "Air Conditioning punch" "linkdata =" "http://www.kongtiaodakong.com/" "linktype =" "framenumber" "linktarget =" "Carousel" "captiontext =" "Chen Rui "" captiontext2 = "" Chen Rui "" enablebuttonwheninfront = "" 1 ""/> ")

%>
<%
Myfile. writeline ("</photos> ")
%>

<%
Myfile. Close
%>

 

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.