However, *ALL I GET* is UTF-8 - it's like .NET
XslTransform is somehow ignoring the new encoding.
I've tried changing the XmlTextWriter encoding from UTF8
to ASCII but neither helps.
Please Help!
Here's my code and stylesheet:
XPathDocument xmlDoc;
XslTransform xslT;
XmlTextWriter myWriter;
myWriter = new XmlTextWriter(
Server.MapPath( "outXML.xml" ),
System.Text.Encoding.UTF8 );
xmlDoc = new XPathDocument(
Server.MapPath( "XMLCompareFiles\\s2v21chp8f11529.xml" ) );
xslT = new XslTransform();
xslT.Load( Server.MapPath
( "Transform2NCR.xslt" ) );
xslT.Transform( xmlDoc, null,
myWriter );
myWriter.Close();
<!----- STYLESHEET ---------->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" encoding="us-ascii" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node
()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<xsl:output omit-xml-declaration="no" method="xml" media-type="text/xml"
indent="no" encoding="iso8859-1"/>
If that doesn't work, try using a StringWriter and not the xmlTextWritter
If that doesn't work do the Transform that takes in two urls (files) and If
i remember, that does not have the encoding problem.
You can also Interop MSXML4 and get rid of all the problems.
Do you need samples?
Joe
"IMarshal" <imar...@swbell.net> wrote in message
news:b06a01c1dc29$16883680$b1e62ecf@tkmsftngxa04...
I tried the new xsl:output directive but it didn't work.
I've now written three procedures, each trying to do the
transform in a different way. One uses an XmlTextWriter
for the stream, another uses StringWriter and the newest
uses MSXML4.0.
Even the MSXML4.0 implementation isn't working for me.
Here's my code (Please give samples!!) :)
FreeThreadedDOMDocument40 xmlDoc = new
FreeThreadedDOMDocument40();
FreeThreadedDOMDocument40 xslDoc =
new FreeThreadedDOMDocument40();
XSLTemplate40 xslT = new
XSLTemplate40();
xmlDoc.async = false;
xmlDoc.load( Server.MapPath
( "XMLCompareFiles\\s2v21chp8f11529.xml" ) );
xslDoc.async = false;
xslDoc.load( Server.MapPath
( "Transform2NCR.xslt" ) );
xslT.stylesheet = xslDoc;
IXSLProcessor myProcessor =
xslT.createProcessor();
myProcessor.input = xmlDoc;
myProcessor.transform();
StreamWriter myStream = new
StreamWriter( Server.MapPath( "outXML.xml" ), false,
System.Text.Encoding.UTF8 );
myStream.Write(
myProcessor.output );
myStream.Close();
>.
>
Joe
"IMarshal" <imar...@swbell.net> wrote in message
news:586c01c1dc31$65ccbfb0$37ef2ecf@TKMSFTNGXA13...
The only solution without writing to the drive was to use MSXML4 and the
ADODB.Stream, setting the charset to "iso-8859-1".
Then returning from the function as a string using the oStream.ReadText()
method.
Joe
"Joe Feser" <nn...@fesersoft.com> wrote in message
news:ue6oHvG3BHA.352@tkmsftngp05...
I only find out IMarshal is IPersist.??
No clue. Yah trust me I know :).
Joe
"Joe Feser" <nn...@fesersoft.com> wrote in message
news:ue6oHvG3BHA.352@tkmsftngp05...
The ADODB Stream did the trick. :) I hope you received
my C# translation of the VB.NET code.
>> Í{ wÀ ? ,q¾ Ö= tñø ìC >
"IMarshal" <imar...@swbell.net> wrote in message
news:b06a01c1dc29$16883680$b1e62ecf@tkmsftngxa04...
If I were to reload the xml data back into an XMLDOM
object and then view the data, it transformed the NCRs
back to the character equivilants - even if the encoding
is set to iso-8859-1. ugh
>.
>
Joe must me the man. I wonder how much hair is left?
IPersistStream
"IMarshal" <imar...@swbell.net> wrote in message
news:087601c1e05a$b50d49f0$35ef2ecf@TKMSFTNGXA11...
Matt, if you get a chance to post the code you're talking
about please do - or let us know the status. My emotional
stability is now brought into question from this whole
affair.
>.
>
> Matt, if you get a chance to post the code you're talking
> about please do - or let us know the status. My emotional
> stability is now brought into question from this whole
> affair.
Well I'm glad you failed the Postal Worker exam. :)
ISerializable
I had a similar problem. The solution I came up with was to write a custom
Encoding class, ISO88591WithNCREncoding (yeah, I know it's an awkward name),
to do the job. By passing an instance of this class to any function
accepting a System.Text.Encoding parameter, ISO-8859-1 encoded text with
embedded NCRs can be automatically generated or read.
As an example, here is a snippet of code from the application I was writing
that required this functionality (non-relevant code, such as error checking,
removed for clarity). This snippet transforms an XML file specified by
xmlFilename using an XSLT file specified by xsltFilename and writes the
result to an ISO-8859-1 encoded file with NCRs specified by outputFilename.
XslTransform xslt = new XslTransform();
xslt.Load(xsltFilename);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFilename);
StreamWriter f = new StreamWriter(outputFilename, false, new
ISO88591WithNCREncoding());
xslt.Transform(xmlDoc, null, f);
Steve W. Brewer
(Remove the hyphens from my email address to send email.)
// ======================================================================
// ISO88591WithNCREncoding Class verison 1.0 July 10, 2002
// ======================================================================
// Copyright ©2002 Steve W. Brewer (st-...@ka-tech.com)
//
// Note: The email address above has been altered in an effort to prevent
// spam. To send me email, first remove the two hyphens from the
// email address.
//
// This class provides an encoding that represents Unicode characters
// as an ISO-8859-1 octet stream. Characters not defined in ISO-8851-1
// are represented in the octet stream as standard HTML/XML numeric
// character references (NCRs). Only decimal NCRs are supported in this
// version of the class.
//
// ======================================================================
using System;
using System.Text;
public class ISO88591WithNCREncoding : Encoding {
const string iso88591 = "ISO-8859-1";
public ISO88591WithNCREncoding() : base() {
}
#region Properties
public override string BodyName {
get {
return Encoding.GetEncoding(iso88591).BodyName;
}
}
public override int CodePage {
get {
return Encoding.GetEncoding(iso88591).CodePage;
}
}
public override string EncodingName {
get {
return Encoding.GetEncoding(iso88591).EncodingName;
}
}
public override string HeaderName {
get {
return Encoding.GetEncoding(iso88591).HeaderName;
}
}
public override bool IsBrowserDisplay {
get {
return Encoding.GetEncoding(iso88591).IsBrowserDisplay;
}
}
public override bool IsBrowserSave {
get {
return Encoding.GetEncoding(iso88591).IsBrowserSave;
}
}
public override bool IsMailNewsDisplay {
get {
return Encoding.GetEncoding(iso88591).IsMailNewsDisplay;
}
}
public override bool IsMailNewsSave {
get {
return Encoding.GetEncoding(iso88591).IsMailNewsSave;
}
}
public override string WebName {
get {
return Encoding.GetEncoding(iso88591).WebName;
}
}
public override int WindowsCodePage {
get {
return Encoding.GetEncoding(iso88591).WindowsCodePage;
}
}
#endregion
#region Public Methods
public override int GetMaxByteCount(int charCount) {
return charCount * 8;
}
public override int GetByteCount(char[] chars, int index,
int count) {
return GetBytes(chars, index, count, null, 0, false);
}
public override int GetBytes(char[] chars, int charIndex,
int charCount, byte[] bytes, int byteIndex) {
return GetBytes(chars, charIndex, charCount, bytes, byteIndex,
true);
}
public override int GetMaxCharCount(int byteCount) {
return byteCount;
}
public override int GetCharCount(byte[] bytes, int index,
int count) {
return GetChars(bytes, index, count, null, 0, false);
}
public override int GetChars(byte[] bytes, int byteIndex,
int byteCount, char[] chars, int charIndex) {
return GetChars(bytes, byteIndex, byteCount, chars, charIndex,
true);
}
#endregion
int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex, bool fillBytes) {
char c;
string s;
ASCIIEncoding asciiEncoding = new ASCIIEncoding();
int startByteIndex = byteIndex;
for (; charCount > 0; charCount--, charIndex++) {
c = chars[charIndex];
if (c <= '\u007f' || (c >= '\u00a0' && c <= '\u00ff')) {
if (fillBytes)
bytes[byteIndex] = System.Convert.ToByte(c);
byteIndex++;
}
else {
s = String.Format("&#{0};", System.Convert.ToUInt16(c));
if (fillBytes)
asciiEncoding.GetBytes(s, 0, s.Length, bytes,
byteIndex);
byteIndex += s.Length;
}
}
return byteIndex - startByteIndex;
}
int GetChars(byte[] bytes, int byteIndex, int byteCount,
char[] chars, int charIndex, bool fillChars) {
char b;
int startCharIndex = charIndex;
StringBuilder sb;
for (;; byteCount--, byteIndex++) {
if (byteCount > 0) {
b = System.Convert.ToChar(bytes[byteIndex]);
if (b != '&') {
if (fillChars) chars[charIndex] = b;
charIndex++;
continue;
}
}
else {
break;
}
byteCount--; byteIndex++;
if (byteCount > 0) {
b = System.Convert.ToChar(bytes[byteIndex]);
if (b != '#') {
if (fillChars) chars[charIndex] = '&';
charIndex++;
if (fillChars) chars[charIndex] = b;
charIndex++;
continue;
}
}
else {
if (fillChars) chars[charIndex] = '&';
charIndex++;
break;
}
sb = new StringBuilder();
for (;;) {
byteCount--; byteIndex++;
if (byteCount > 0) {
b = System.Convert.ToChar(bytes[byteIndex]);
if (((b < '0' || b > '9') && b != ';') ||
sb.Length > 0 &&
UInt32.Parse(sb.ToString()) > UInt16.MaxValue ) {
if (fillChars) chars[charIndex] = '&';
charIndex++;
if (fillChars) chars[charIndex] = '#';
charIndex++;
if (fillChars)
sb.ToString().CopyTo(0, chars, charIndex,
sb.Length);
charIndex += sb.Length;
if (fillChars) chars[charIndex] = b;
charIndex++;
break;
}
else if (b != ';') {
sb.Append(b);
}
else {
if (fillChars)
chars[charIndex] =
System.Convert.ToChar(UInt16.Parse(sb.ToString()));
charIndex++;
break;
}
}
else {
if (fillChars) chars[charIndex] = '&';
charIndex++;
if (fillChars) chars[charIndex] = '#';
charIndex++;
if (fillChars)
sb.ToString().CopyTo(0, chars, charIndex,
sb.Length);
charIndex += sb.Length;
break;
}
}
}
return charIndex - startCharIndex;
}
}