Solved

weird problem loading XML file with ASP/JScript

Posted on 2001-09-11
10
275 Views
Last Modified: 2008-03-03
I'm using MSXML v3.

When I open an XML file from the browser (IE5.5), it is
able to display the chinese characters in the XML file.

However, if I use ASP/JScript, load the XML file and
display the data in each node, the Chinese characters
turned to question marks!

How can I solve this?

My code as follows:
===
<%
    Response.Write
("<html><head><title>loadXML</title><meta charset=UTF-
8></head>");
   
     var dom = Server.CreateObject("MSXML.DomDocument");
         
     dom.preserveWhiteSpace = true;

     dom.load(Server.MapPath
("xadmin/catalog/imports/testexport.xml"));

     var parseError = dom.parseError;
     if (parseError.errorCode != 0) {
          var e = new Error("Error: line " +
parseError.line + "; reason = " + parseError.reason);
          throw(e);
     }
     
     
     //Set root to the XML document's root element,
COLLECTION:
     var root = dom.documentElement;
     var e, child;
     e = new Enumerator(root.childNodes);   //Create
Enumerator
     for (;!e.atEnd();e.moveNext())
     {
          child = e.item();
          Response.Write(child.text + "<br>");
     }
====


Note: For those who want a sample copy of the XML file,
pls email me at slok00@yahoo.com
0
Comment
Question by:slok
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 4

Expert Comment

by:chabaud
ID: 6476061
Do you try UTF-16 instead of UTF-8 ?
0
 
LVL 1

Expert Comment

by:sandaruwan
ID: 6476175
Save XML file as a Unicode Text file instead of Plain Text file.
Or...
Add encoding information in to the xml file as shown below.
<?xml version="1.0" encoding="ISO-8859-1"?>
 
Hope this hepls.

Fore more info on encoding xml reffer following page.
http://www.w3schools.com/xml/xml_encoding.asp

- Sandaruwan -
0
 
LVL 1

Expert Comment

by:sandaruwan
ID: 6476189
Another thing...

If you add encoding info. to the xml, then use that encoding method in the html file as well. Otherwise it will give errors.
e.g.
Response.Write("<html><head><title>loadXML</title><meta charset=ISO-8859-1></head>");

- Sandaruwan -
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:slok
ID: 6476689
hi guys, I would need to use UTF-8 as stated in my
question that I'm supporting Chinese characters and
also found in my sample code.


what I would like to find out is why is the same parser
on my machine behave differently when I open it from the
browser and loading it through ASP/JScript.

thanks
0
 
LVL 4

Expert Comment

by:chabaud
ID: 6478668
When you open Xml directly, it uses the character encoding specified in Xml header (or unicode marker if any).

Throught asp, you generate Html string. The encoding may be different.
0
 
LVL 2

Expert Comment

by:bbala
ID: 6479728
Try session.code page value.

I dont know exact codepage value for chinese character
sorry...


<%
'Use the exact codepage value here
session.codepage=#chinesecodepagevalue
%>

regards,
bala
0
 
LVL 3

Author Comment

by:slok
ID: 6479875
sorry, I'm new to ASP.

can you elaborate on the codepage value.
what's the equivalent for say English.
0
 
LVL 15

Accepted Solution

by:
robbert earned 100 total points
ID: 6485786
Codepage should work.

<%
Session.CodePage = XXXX
%>

would set the codepage for all ASPages.

<%@ CodePage=XXXX %>
or
<%@ Language=VBScript CodePage=XXXX%>

at the top of the script, would set the codepage for the current ASPage.

You'll find the codepage ID ("XXXX") at http://msdn.microsoft.com/library/default.asp?url=/workshop/Author/dhtml/reference/charsets/charset4.asp - in the table column "FamilyCodePage".
0
 
LVL 3

Author Comment

by:slok
ID: 6487451
it still doesn't work.

this is what I have done.

==
<%@ Language=JScript Codepage="utf-8" %>

===
0
 
LVL 3

Author Comment

by:slok
ID: 6487939
finally, I managed to find the correct codepage for utf-8.
it's 65001.

I'm giving the points to Robbert as he helps me jumpstart
in terms of coding in ASP. It's a very trivial code
but for someone who has not touched MS related stuffs
for 5 years... its a great leap.

thanks also to everyone who has chip in
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Data at the root level is invalid. Line 1, position 1 8 291
Change to event 1 129
c# code 19 72
CURL sending XML without spaces PHP 5 33
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question