In one of the projects that I’m working in we had to do some server-side transforming using MSXML. Everything went well until we transformed some pages using German umlauts. The encoding in the XML file was correctly set but the result was completely ignoring the umlauts, replacing them with the question mark sign.
The code was using the transformNode() method. In this case MSXML is always using internally a string format called BSTR which is UTF-16 encoded data. So whatever encoding is set it will be ignored.
The solution is to use transformNodeToObject() method which is keeping the encoding settings.
You can download the complete Notes Dabatase from here: MSXMLEnc.nsf
Sub transform() On Error Goto errorHandler Const urlBase = “http://localhost/MSXMLEnc.nsf” Dim xmlDoc As Variant, xslDoc As Variant Dim xmlDocURL As String, xslDocURL As String xmlDocURL = urlBase + “/article.xml” xslDocURL = urlBase + “/article.xsl” ‘ initthe XML and XSL Set xmlDoc = CreateObject(“Msxml2.DOMDocument.3.0″) xmlDoc.async = False Set xslDoc = CreateObject(“Msxml2.DOMDocument.3.0″) xslDoc.async = False ‘ load the XML and XSL xmlDoc.load( xmlDocURL ) xslDoc.load( xslDocURL ) ‘ we need to do the transformation using the transformNodeToObject() ‘method and a stream implementing the IStream interface. ‘ If not the character encoding is not kept Dim adoStream As Variant Set adoStream = CreateObject(“ADODB.Stream”) adoStream.Open adoStream.Type = 2 ‘2 -> adTypeText -> Text data adoStream.Charset = “ISO-8859-15″ ‘transform and store the result in stream Call xmlDoc.transformNodeToObject(xslDoc, adoStream) ‘place in a file and attach it Dim strDocUNID As String strDocUNID = storeHTML( adoStream ) adoStream.Close Set adoStream = Nothing Set xmlDoc = Nothing Set xslDoc = Nothing Print “[” + urlBase “/0/” + strDocUnid + “/$file/article.html]” Exit Sub errorHandler: Print “Error #”+Cstr(Err)+” <”+Error$+“>in MSXML Transformation on line “ +Cstr(Erl) Exit Sub End Sub
provided by Julian Robichaux at nsftools.com.