• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

weird problem loading XML file with ASP/JScript

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
slok
Asked:
slok
  • 4
  • 2
  • 2
  • +2
1 Solution
 
chabaudCommented:
Do you try UTF-16 instead of UTF-8 ?
0
 
sandaruwanCommented:
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
 
sandaruwanCommented:
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
Industry Leaders: 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!

 
slokAuthor Commented:
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
 
chabaudCommented:
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
 
bbalaCommented:
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
 
slokAuthor Commented:
sorry, I'm new to ASP.

can you elaborate on the codepage value.
what's the equivalent for say English.
0
 
robbertCommented:
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
 
slokAuthor Commented:
it still doesn't work.

this is what I have done.

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

===
0
 
slokAuthor Commented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now