Hello Everyone,
I have some problems about "charset" in the transformation result with different versions of MSXML.
The code below will transform XML to HTML with MSXML3.0
Dim xmlDoc As New MSXML2.DOMDocument
xmlDoc.async = False
Dim strXML As String
strXML = "<Results><ElapsedTime>3000</ElapsedTime></Results>"
xmlDoc.loadXML(strXML)
Dim xslDoc As New MSXML2.FreeThreadedDOMDocument
xslDoc.async = False
Dim strXSL As String
strXSL = "C:\Test.xsl"
xslDoc.load(strXSL)
Dim xslt As New MSXML2.XSLTemplate
xslt.stylesheet = xslDoc
Dim xslProc As MSXML2.IXSLProcessor
xslProc = xslt.createProcessor
xslProc.input = xmlDoc
xslProc.transform()
Debug.Print(xslProc.output)
================================
The content of "Test.xsl" is,
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Results">
<html>
<head>
<title>Report</title>
</head>
</html>
</xsl:template>
</xsl:stylesheet>
===============================
The output is,
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
<title>Report</title>
</head>
</html>
I'm not sure why the charset is always set as "UTF-16" with MSXML3.0
=========================
Then I change code to use MSXML4, like this,
Dim xmlDoc As New MSXML2.DOMDocument40
...
Dim xslDoc As New MSXML2.FreeThreadedDOMDocument40
...
Dim xslt As New MSXML2.XSLTemplate40
...
=====================
This time, the output is,
<html>
<head>
<META http-equiv="Content-Type" content="text/html">
<title>Report</title>
</head>
</html>
No charset is output in MSXML4.0.
=====================
Can you please tell me which one is right? Why the differences happens?