 |
 |
 |
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.
|
 | 

|  |
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.
|  |
| |
 |
 |
 |