I am trying to generate a text file for each XML file from a third party system using SSIS package script task and XSLT. Sometimes few special characters appear in these XML files. One such character is the right single quotation mark ’. Because of this the script task fails with message Invalid Character in the given encoding. XML looks like below:
<firstelement>
<Id>1112</Id>
<State>AP</State>
<City>E’Godavari</City>
</firstelement>
XSLT is
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="text" encoding="iso-8859-1"/>
<xsl:template match="/firstelement">
<xsl:text>|@|Id|@|State|@|City|@|</xsl:text>
<xsl:text>
</xsl:text>
|@|<xsl:value-of select="Id"/>|@|<xsl:value-of select="State"/>|@|<xsl:value-of select="City"/>|@|
</xsl:template>
</xsl:stylesheet>
The Script task code is below:
var xmlPath = @"C:\Cities.xml";
var xsltPath = @"C:\Cities.xslt";
var outputTxt = @"C:\Cities.txt";
var xslCompiledTransformObj = new XslCompiledTransform();
xslCompiledTransformObj.Load(xsltPath);
xslCompiledTransformObj.Transform(xmlPath, outputTxt);
I have tried changing the encoding to UTF-8 in XSLT file's xsl:output
tag but i was still getting same error.