Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Microsoft.XMLDOM output UTF-8 1

Status
Not open for further replies.

MakeItSo

Programmer
Oct 21, 2003
3,316
DE
Hello friends,

I am having trouble correctly displaying XML content which I load from an ASP.
My XML is encoded in UTF-8, yet the transformed HTML output is encoded UTF-16!
That, of course, causes all special characters to display as junk.
Can you help me out here?

This is my ASP code handling the XML data:
Code:
	Dim objXML
	Dim objXSL
	Dim strHTML
	
	'Load the XML File
'determine, which file to load*****
        fil= "xml/" & lang & "/" & session("file") & ".xml"
'********
	Set objXML = Server.CreateObject("Microsoft.XMLDOM")
	objXML.async = False
	objXML.load(Server.MapPath(fil))
	'Load the XSL File
	Set objXSL = Server.CreateObject("Microsoft.XMLDOM")
	objXSL.async = False
	objXSL.load(Server.MapPath("andy.xsl"))
	
	' Transform the XML file using the XSL stylesheet
	strHTML = objXML.transformNode(objXSL)
	
	Set objXML = Nothing
	Set objXSL = Nothing
	
	Response.Write strHTML

This is my XML header:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="andy.xsl" ?>
My XSL header:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
And the resulting output:
Code:
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">

What the hell? [3eyes]

Sure: UTF-8 + UTF-8 = UTF-16, do the math...
[bigcheeks]

Strange things...

Thanks in advance!
Andy

[blue]Help us, join us, participate
IAHRA - International Alliance of Human Rights Advocates[/blue]
 
[1] In your stylesheet, at the top level you have (I hope) the element xsl:eek:utput? If not, add it in like this.
[tt]
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[blue]<xsl:eek:utput method="html" encoding="utf-8" />[/blue]
[/tt]
[2] In the asp proper, use transformnodetoobject instead of transformnode. The output is streamed to the response object. Like this.
[tt]
' Transform the XML file using the XSL stylesheet
[red]'[/red]strHTML = objXML.transformNode(objXSL)
[blue]objXML.transformNodeToObject objXSL,Response[/blue]

Set objXML = Nothing
Set objXSL = Nothing

[red]'[/red]Response.Write strHTML
[/tt]
And now things are set to go.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top