Solved

weird problem loading XML file with ASP/JScript

Posted on 2001-09-11
10
270 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

19 Experts available now in Live!

Get 1:1 Help Now