Hi, my code is outputting some weird character at the very start of my XSLT output XML and neither Visual Studio 2008 or notepad show it up. But it's definitely there because VS lets me delete it and will then auto-format the XML properly. How do I stop this? Here's my code:
// create the readers for the xml and xsl
XmlReader reader = XmlReader.Create(
new StringReader(LoadFileAsString(MapPath(xslPath)))
);
XmlReader input = XmlReader.Create(
new StringReader(LoadFileAsString(MapPath(xmlPath)))
);
// create the xsl transformer
XslCompiledTransform t = new XslCompiledTransform(true);
t.Load(reader);
// create the writer which will output the transformed xml
StringBuilder sb = new StringBuilder();
//XmlWriterSettings tt = new XmlWriterSettings();
//tt.Encoding = Encoding.Unicode;
XmlWriter results = XmlWriter.Create(new StringWriter(sb));//, tt);
// write the transformed xml out to a stringbuilder
t.Transform(input, null, results);
// return the transformed xml
WriteStringAsFile(MapPath(outputXmlPath), sb.ToString());
public static string LoadFileAsString(string fullpathtofile)
{
string a = null;
using (var sr = new StreamReader(fullpathtofile))
a = sr.ReadToEnd();
return a;
}
public static void WriteStringAsFile(string fullpathtofile, string content)
{
File.WriteAllText(fullpathtofile, content.Trim(), Encoding.Unicode);
}