Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: XSLT transformation output contains utf-16 instead of utf-8 XSLT transformation output contains utf-16 instead of utf-8To: NULL Date: 11/1/2004 5:13:00 PM
I used the code provided by Oleg Tkachenko, but, the resuling xml output still contained xml declaration as
<?xml version="1.0" encoding="utf-16"?>.
Reviewing the TextWriter's Encoding, I noticed it as overridable property and then I used a class derived from StringWriter as shown below and replaced the StringWriter with VStringWriter in XSL processing code.
using System.IO;
/// <summary>
/// Used to Write output of XSL transform so that the output
/// contains declaration with utf-8 attribute
/// </summary>
public class VStringWriter : StringWriter
{
private Encoding m_encoding = Encoding.UTF8;
public VStringWriter(Encoding enc)
: base()
{
m_encoding = enc;
}
public override Encoding Encoding
{
get { return m_encoding; }
}
}
...
public XmlDocument ProcessDataWithXSL(XmlDocument xmlDocWithUTF8Decl, string strXSLWithUTF8Decl)
{
try
{
XslTransform xsltTransformer = new XslTransform();
xsltTransformer.Load(new XmlTextReader(
new StringReader(strXSLWithUTF8Decl)),null,null);
// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials =
System.Net.CredentialCache.DefaultCredentials;
XPathDocument xmlDoc = new XPathDocument(
new StringReader(xmlDocWithUTF8Decl.OuterXml));
VStringWriter sw = new VStringWriter(Encoding.UTF8);
xsltTransformer.Transform(xmlDoc, null, sw, resolver);
XmlDocument xmlDataDoc = new XmlDocument();
string strData = sw.ToString();
xmlDataDoc.LoadXml(strData);
return xmlDataDoc;
}
catch(Exception ex)
{
throw new ApplicationException(
"Failed to process xml data", ex);
}
}
This worked for me. There might be some typo here because I modified function and variable names.
Thanks and good luck.
---
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
