Welcome to WebmasterWorld Guest from 18.206.168.65

Forum Moderators: ocean10000

Message Too Old, No Replies

Help with XML and VBScript

     
5:07 am on Aug 16, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 17, 2002
posts:2251
votes: 0


I've spent an hour on this to no avail. Will someone please help me?

I am parsing an XML file created via a Twitter API call with VBScript in a .vbs file. The XML file is fine, no problems. There are HTML entities in the file that are supposed to represent Japanese characters.

<text>&#12414;&#12384;</text>

When my script gets to this line and tries to write the entities to a text file, the script crashes with an, Invalid procedure call or argument, error on the line where I try to write to the text file. This is the code on that line. The error occurs on the second line.

TextStr = XMLLineNode.selectSingleNode("text").Text
[...]
TextFile.WriteLine "<div class=""twitter_text"">" & TextStr & "</div>"

TIA.

5:59 am on Aug 16, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


Gary is it a mix of English and Japanese or pure Japanese? I am thinking it is an encoding issue because of the mix of English and Japanese and its blowing its cookies all over the table because of it.
2:40 pm on Aug 16, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 17, 2002
posts:2251
votes: 0


its blowing its cookies all over the table because of it

Quite the graphic description, Owen. :)

is it a mix of English and Japanese or pure Japanese

It's largely English with occasional Japanese.

Curiously, the same exact code works fine in an .asp file, which is where I first tested it before moving it to a .vbs file cause Twitter kept alternating between speedy and sluggish retrieval times, so I decided to do the conversion once every 30 minutes or so and store it in a text file.

The only difference between the two formats was with .asp I saw question marks instead of actual Japanese characters when displaying the .txt file in the browser, while in .vbs it crashed when writing the HTML entities to the .txt file during the xml conversion.

4:16 pm on Aug 16, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3



Example Turns on Unicode instead of pure ASCII.
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True, True)

CreateTextFile Method [msdn.microsoft.com]

5:16 pm on Aug 16, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 17, 2002
posts:2251
votes: 0


Thanks, Owen. It's not crashing anymore. :)

I have a new problem now though. And I'm not sure how to show you all what it is because the forum software makes a mess of it. So let me see if I can explain it.

Instead of writing the HTML entities to the .txt file, it's writing the actual characters. That's fine I suppose. But when I try to display them on an .asp page what I see is all question marks.

Clearly I don't have a lot of experience with displaying foreign languages. This is the first time I've ever needed to display something in a non-English alphabet. So what's the right way to do it please?

5:27 pm on Aug 16, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


I think you will need to encode the output. But since you are not doing it with asp classic but via a VB script, you will not have access to the standard html encode script. I found an example of one on CodeProject that you can use.

VBScript HTML Encode [codeproject.com]

6:41 pm on Aug 16, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 17, 2002
posts:2251
votes: 0


Thanks again, Owen.

Combining that HTMLEncode function and a Regular Expression so that I only encode the HTML entities gives me characters instead of question marks in the text file I'm creating.

Next I need to figure out how to make those characters from the text file display as Japanese symbols instead of question marks on the web page.

12:08 am on Aug 17, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 17, 2002
posts:2251
votes: 0


Reading the XML file was causing the character encoding problem. It converted the string from Unicode to ASCII. I'm reading it as a text file and doing my parsing with regular expressions now and it works fine. It's a very small file so it's no biggie to do it this way.