Solved

weird problem loading XML file with ASP/JScript

Posted on 2001-09-11
10
271 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting BLOB to XMLTYPE 12 102
PHP and Soap 3 46
c# code 19 69
msxml3.dll error '80072efd' A connection with the server could be not established 8 33
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now