G
Guest
hi all,
please review the following code snipped, my goal is just to transform a
document.
The problem is that XmlWriter.Create do not honor passed
Trans.OutputSettings. The debuggin shows that Trans.OutputSettings.Encoding
is set to {System.Text.UTF8Encoding}, but OutWriter.Settings.Encoding is
{System.Text.UnicodeEncoding} after the call to Create().
Can you explain it and provide a workaround?
XmlDocument docXsl = new XmlDocument();
docXsl.LoadXml(transform);
XslCompiledTransform Trans = new XslCompiledTransform();
Trans.Load(docXsl);
StringBuilder Out = new StringBuilder();
XmlWriter OutWriter = XmlWriter.Create(Out, Trans.OutputSettings
);
Trans.Transform(doc, OutWriter);
here are the beginnings of the xml and stylesheet invloved:
doc:
<?xml version ="1.0" encoding="utf-8"?>
docXsl:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xslutput method="html" omit-xml-declaration="yes" encoding="UTF-8" />
please review the following code snipped, my goal is just to transform a
document.
The problem is that XmlWriter.Create do not honor passed
Trans.OutputSettings. The debuggin shows that Trans.OutputSettings.Encoding
is set to {System.Text.UTF8Encoding}, but OutWriter.Settings.Encoding is
{System.Text.UnicodeEncoding} after the call to Create().
Can you explain it and provide a workaround?
XmlDocument docXsl = new XmlDocument();
docXsl.LoadXml(transform);
XslCompiledTransform Trans = new XslCompiledTransform();
Trans.Load(docXsl);
StringBuilder Out = new StringBuilder();
XmlWriter OutWriter = XmlWriter.Create(Out, Trans.OutputSettings
);
Trans.Transform(doc, OutWriter);
here are the beginnings of the xml and stylesheet invloved:
doc:
<?xml version ="1.0" encoding="utf-8"?>
docXsl:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xslutput method="html" omit-xml-declaration="yes" encoding="UTF-8" />