BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


Microsoft ASP
WAP with ASP - starting the WAP adventure
ASP/XML Guest Book
Include an ASP-file in XSL (JITIC Solution)
Read/write data with VB using ASP pages


 
 

<< LAMP 


By Martin Rowlinson (aka Marrow)
First Posted 03/07/2002
Times viewed 1140

FAQ - My ASP MSXML transformation always outputs UTF-16?


Summary ...and the answer to why it sometimes appears that MSXML completely ignores the

This is an FAQ, asked in many newsgroups and discussions lists on almost a weekly (if not daily) basis...

In an ASP page using MSXML (3 or 4) the transformation result is returned as UTF-16 despite the fact that a <xsl:output encoding=.../> has been specified in the stylesheet.  This is invariably down to the use of the .transformNode() method being used, e.g.

  Response.write(MyDom.transformNode(MyXSLDOM))

The problem with using the .transformNode() is that the model for this method is that it returns a BSTR.  And a BSTR must, by its nature, be encoded as UTF-16.  This is why MSXML ignores the <xsl:output encoding=.../> and always returns HTML/XML that is encoded as UTF-16 and says that it is encoded as such (either with an XML declaration or by placing a content=text/html; charset=UTF-16 in the HTML header).  So it is very much a case of a square peg into a round hole - if .transformNode() returns UTF-16 (a BSTR) you cannot place another encoding into this return string.

The solution is to avoid using the .transformNode() method altogether.  Instead it is better to use the .TransformNodeToObject() method - which can be used to write the transformation result directly out to a 'stream' (and a stream can be encoded in any way), e.g.

  MyDom.transformNodeToObject(MyXSLDOM,Response)

The result of the transformation is then written to the ASP response object.

The other alternative is to use the IXSLTemplate and IXSLProcessor interfaces of MSXML (see your MSXML SDK for more info).  The IXSLProcessor interface can also have it's .output property assigned as an object (that supports the IStream .write method - which the ASP Response object supports) prior to executing the .transform() method.  The transformation result of the IXSLProcessor is then written directly out to that stream.

Cheers - Marrow

Additional information

Further additional information


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< LAMP 





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML