Solved

weird problem loading XML file with ASP/JScript

Posted on 2001-09-11
10
272 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
installing and using WTP plugin eclipse MARS 3 111
VB.NET and XML parsing 6 76
PHP and Soap 3 51
Fixing Non-Standard characters in text 8 103
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

785 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