Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 7th, 2009, 12:02 AM
Registered User
 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using ASP classic filesystem object to retrieve a xml file turns characters into Chin


Hello;

I have a pretty interesting problem here.

I read an xml file from the server using the fileSystem object. However...the text "magically" turn into Chinese characters.

If I take a look at the xml file in notepad it seems fine (normal English xml), but as soon as I read the individual lines of the file using the filesystem object I get the weird characters.

The code I use to access the file is pretty standard:

var FileObj,this_file;
var txt_arr = new Array();

FileObj = Server.CreateObject("Scripting.FileSystemObject");
this_file = FileObj.OpenTextFile(Server.MapPath("xmlfile.xml") );

while(!this_file.AtEndOfStream)
{
txt_arr[txt_arr.length] = this_file.ReadLine();
}


Response.Write(txt_arr);

Has anybody ever come across something like this before?
Reply With Quote
  #2 (permalink)  
Old March 7th, 2009, 08:07 AM
Friend of Wrox
Points: 894, Level: 11
Points: 894, Level: 11 Points: 894, Level: 11 Points: 894, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: London, , United Kingdom.
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

Hi

Welcome to P2P.
All I can think is that the file, or possibly your browser, is in some sort of unicode encoding, which may look fine in Notepad but cause problems in the browser.
With the xml file open in Notepad, click File->Save As. At the bottom of the save dialog, there is an Encoding dropdown. Make sure that says Ansi, instead of Unicode or UTF8, and save it.

Note also that Internet Explorer 7 will find the xml tag, think this is an actual xml file being output and attempt to render it as such, whilst Firefox doesn't. This may also be something worth investigating.

Your code is certainly fine, as I dropped it as-is into my own asp file and ran it without any problems.

Hope this helps
Phil
Reply With Quote
  #3 (permalink)  
Old March 7th, 2009, 08:32 AM
Registered User
 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default RE: Using ASP classic filesystem object to retrieve a xml file turns.....

Thanks for the pointers Philip.

Quote:
All I can think is that the file, or possibly your browser, is in some sort of unicode encoding, which may look fine in Notepad but cause problems in the browser.
Good point, but the actual code I use writes the xml file back to the server after making a couple of changes, so in the normal runtime environment it is'nt outputed to the screen.

I checked both files (the file existing on the server and the one created by writing it through the filesystem object) in Dreamweaver and this is how they look.

Basically this:

Code:
<CONFIG>
<TITLE name="Dogs - Abnormal Behaviour - Normal Behaviour"><![CDATA[Introduction Here
]]></TITLE>
<MOVIE url="flashvideo/1.flv" autoplay="true" />
<DATA>
<TEXTS s="0" t="Dogs - problem behaviour - normal behaviour" imgurl="fslides/slide1.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="21.239" t="What are dogs designed to do?" imgurl="fslides/slide2.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="33.13" t="Species responses" imgurl="fslides/slide3.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="62.898" t="Behaviour of the dogs ancestors" imgurl="fslides/slide4.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="142.767" t="Influences on behaviour" imgurl="fslides/slide5.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="173.623" t="Feeling safe" imgurl="fslides/slide6.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="244.832" t="Acquiring food" imgurl="fslides/slide7.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="349.48" t="Acquiring food" imgurl="fslides/slide8.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="431.637" t="Acquiring food" imgurl="fslides/slide9.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="505.864" t="Acquiring food" imgurl="fslides/slide10.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="597.079" t="Reproduction" imgurl="fslides/slide11.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="705.008" t="Social contacts" imgurl="fslides/slide12.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="826.689" t="Further influences on behaviour" imgurl="fslides/slide13.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
<TEXTS s="899.154" t="Summary" imgurl="fslides/slide14.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
</DATA>
</CONFIG>
Becomes this:

Code:
<CONFIG>
਍ऀ㰀吀䤀吀䰀䔀 渀愀洀攀㴀∀䐀漀最猀 ⴀ 䄀戀渀漀爀洀愀氀 䈀攀栀愀瘀椀漀甀爀 ⴀ 一漀爀洀愀氀  䈀攀栀愀瘀椀漀甀爀∀㸀㰀℀嬀䌀䐀䄀吀䄀嬀䤀渀琀爀漀搀甀挀琀椀漀渀 䠀攀爀攀㰀戀爀㸀崀崀㸀㰀⼀吀䤀吀䰀 䔀㸀ഀഀ
<MOVIE url="flashvideo/1.flv" autoplay="true" />
਍ऀ㰀䐀䄀吀䄀㸀ഀഀ
XTS>
਍ऀऀ㰀吀䔀堀吀匀 猀㴀∀㈀㄀⸀㈀㌀㤀∀ 琀㴀∀圀栀愀琀 愀爀攀 搀漀最猀 搀攀猀椀最渀攀搀 琀漀  搀漀㼀∀ 椀洀最甀爀氀㴀∀昀猀氀椀搀攀猀⼀猀氀椀搀攀㈀⸀樀瀀最∀ 㸀㰀℀嬀䌀䐀䄀吀䄀嬀䤀渀琀爀漀搀甀 挀琀椀漀渀 䠀攀爀攀㰀戀爀㸀崀崀㸀㰀⼀吀䔀堀吀匀㸀ഀഀ
<TEXTS s="33.13" t="Species responses" imgurl="fslides/slide3.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
਍ऀऀ㰀吀䔀堀吀匀 猀㴀∀㘀㈀⸀㠀㤀㠀∀ 琀㴀∀䈀攀栀愀瘀椀漀甀爀 漀昀 琀栀攀 搀漀最猀 愀渀挀攀 猀琀漀爀猀∀ 椀洀最甀爀氀㴀∀昀猀氀椀搀攀猀⼀猀氀椀搀攀㐀⸀樀瀀最∀ 㸀㰀℀嬀䌀䐀䄀吀䄀嬀䤀渀琀爀漀 搀甀挀琀椀漀渀 䠀攀爀攀㰀戀爀㸀崀崀㸀㰀⼀吀䔀堀吀匀㸀ഀഀ
<TEXTS s="142.767" t="Influences on behaviour" imgurl="fslides/slide5.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
਍ऀऀ㰀吀䔀堀吀匀 猀㴀∀㄀㜀㌀⸀㘀㈀㌀∀ 琀㴀∀䘀攀攀氀椀渀最 猀愀昀攀∀ 椀洀最甀爀氀㴀∀昀猀氀 椀搀攀猀⼀猀氀椀搀攀㘀⸀樀瀀最∀ 㸀㰀℀嬀䌀䐀䄀吀䄀嬀䤀渀琀爀漀搀甀挀琀椀漀渀 䠀攀爀攀㰀戀爀㸀崀崀 㸀㰀⼀吀䔀堀吀匀㸀ഀഀ
<TEXTS s="244.832" t="Acquiring food" imgurl="fslides/slide7.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
਍ऀऀ㰀吀䔀堀吀匀 猀㴀∀㌀㐀㤀⸀㐀㠀∀ 琀㴀∀䄀挀焀甀椀爀椀渀最 昀漀漀搀∀ 椀洀最甀爀氀㴀∀昀猀 氀椀搀攀猀⼀猀氀椀搀攀㠀⸀樀瀀最∀ 㸀㰀℀嬀䌀䐀䄀吀䄀嬀䤀渀琀爀漀搀甀挀琀椀漀渀 䠀攀爀攀㰀戀爀㸀崀 崀㸀㰀⼀吀䔀堀吀匀㸀ഀഀ
<TEXTS s="431.637" t="Acquiring food" imgurl="fslides/slide9.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
਍ऀऀ㰀吀䔀堀吀匀 猀㴀∀㔀 㔀⸀㠀㘀㐀∀ 琀㴀∀䄀挀焀甀椀爀椀渀最 昀漀漀搀∀ 椀洀最甀爀氀㴀∀昀 猀氀椀搀攀猀⼀猀氀椀搀攀㄀ ⸀樀瀀最∀ 㸀㰀℀嬀䌀䐀䄀吀䄀嬀䤀渀琀爀漀搀甀挀琀椀漀渀 䠀攀爀攀㰀戀爀 㸀崀崀㸀㰀⼀吀䔀堀吀匀㸀ഀഀ
<TEXTS s="597.079" t="Reproduction" imgurl="fslides/slide11.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
਍ऀऀ㰀吀䔀堀吀匀 猀㴀∀㜀 㔀⸀  㠀∀ 琀㴀∀匀漀挀椀愀氀 挀漀渀琀愀挀琀猀∀ 椀洀最甀爀氀㴀∀ 昀猀氀椀搀攀猀⼀猀氀椀搀攀㄀㈀⸀樀瀀最∀ 㸀㰀℀嬀䌀䐀䄀吀䄀嬀䤀渀琀爀漀搀甀挀琀椀漀渀 䠀攀爀攀㰀戀 爀㸀崀崀㸀㰀⼀吀䔀堀吀匀㸀ഀഀ
<TEXTS s="826.689" t="Further influences on behaviour" imgurl="fslides/slide13.jpg" ><![CDATA[Introduction Here
]]></TEXTS>
਍ऀऀ㰀吀䔀堀吀匀 猀㴀∀㠀㤀㤀⸀㄀㔀㐀∀ 琀㴀∀匀甀洀洀愀爀礀∀ 椀洀最甀爀氀㴀∀昀猀氀椀搀攀猀⼀ 猀氀椀搀攀㄀㐀⸀樀瀀最∀ 㸀㰀℀嬀䌀䐀䄀吀䄀嬀䤀渀琀爀漀搀甀挀琀椀漀渀 䠀攀爀攀㰀戀爀㸀崀崀㸀㰀⼀吀 䔀堀吀匀㸀ഀഀ
</DATA>
਍㰀⼀䌀伀一䘀䤀䜀㸀ഀഀ
਍
Amazing is'nt it?
Reply With Quote
  #4 (permalink)  
Old March 7th, 2009, 03:46 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I tried everything I could to repro what you are seeing without any success at all. My output is normal in all circumstances. So I have to believe that the problem is in your original source file, as Mr. Cole noted.
Reply With Quote
  #5 (permalink)  
Old March 8th, 2009, 11:09 AM
Registered User
 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, you could be right Pedant and Mr Cole. I'll take a closer look at the original XML file again.

Thank you very much for your time though.
Reply With Quote
  #6 (permalink)  
Old March 8th, 2009, 03:07 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

He posted this in www.aspmessageboard.com, as well, and uploaded the actual file there.

From my remarks in that forum:

*********

Yep, exactly as predicted. It is a UNICODE FILE!

All you had to do was open it in NOTEPAD and then do SAVE AS... and Notepad would have shown you that it was going to save it as Unicode by default. Meaning that it *is* a Unicode file to start with.

Now go read the docs on Scripting.FileSystemObject.OpenTextFile:
http://msdn.microsoft.com/en-us/libr...4s(VS.85).aspx

See what it says there?
Quote:
format
Optional. One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.
So now change your code to do
Code:
this_file = FileObj.OpenTextFile(Server.MapPath("mediaeasy.xml"),1,false,-1 );
Voila! It works.

Note that to write the text back OUT as Unicode you will need to read the docs for CreateTextFile (or use OpenTextFile and overwrite).
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
VB6 and XML File with International Characters mishi XML 5 December 13th, 2004 01:19 PM
VB6 and XML File with International Characters mishi Pro VB 6 0 December 13th, 2004 11:27 AM
Using The FileSystem Object Ben Horne Classic ASP Basics 1 December 1st, 2003 08:21 PM



All times are GMT -4. The time now is 06:25 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.