Итак, я пытаюсь преобразовать xml-файл, который использует xsl-файл, а затем преобразовать оба из них в html, который я могу связать с объектом WebBrowser. Вот что у меня до сих пор не работает:
protected string ConvertXSLAndXMLToHTML(string xmlSource, string xslSource)
{
string resultDoc = Application.StartupPath + @"\result.html";
string htmlToPost;
try
{
XPathDocument myXPathDoc = new XPathDocument(xmlSource);
XslTransform myXslTrans = new XslTransform();
//load the Xsl
myXslTrans.Load(xslSource);
//create the output stream
XmlTextWriter myWriter = new XmlTextWriter(resultDoc, null);
//do the actual transform of Xml
myXslTrans.Transform(myXPathDoc, null, myWriter);
myWriter.Close();
StreamReader stream = new StreamReader(resultDoc);
htmlToPost = stream.ReadToEnd();
stream.Close();
File.Delete(resultDoc);
return (htmlToPost);
}
catch (FileNotFoundException fileEx)
{
MessageBox.Show("File Not Found: " + fileEx.FileName, "File Not Found Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
catch (Exception ex)
{
MessageBox.Show("General Exception: " + ex.Message, "Exception Thrown" , MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
}
Этот код находится в функции, которая возвращает htmlToPost, а возвращаемые данные привязываются к веб-браузеру следующим образом:
// webReport is the WebBrowser object
// htmlString is the html passed to the function
// that will bind the html text to the WebBrowser object
webReport.Navigate("about:blank");
IHTMLDocument2 test = (IHTMLDocument2)webReport.Document.DomDocument;
test.write(htmlString);
webReport.Document.Write(string.Empty);
webReport.DocumentText = htmlString;
Я знаю, что XslTransform устарел, но все примеры в сети используют его, поэтому я использую его.
Я получаю следующую ошибку:
Произошла ошибка во время выполнения. Вы хотите отладить?
Линия: 177
Ошибка: ожидается ')'
Это происходит, когда этот код пытается выполнить:
IHTMLDocument2 test = (IHTMLDocument2)webReport.Document.DomDocument;
test.write(htmlString); //this is the actual line that causes the error and it traces into assembly code.
Заранее благодарим за любую помощь, которую вы можете оказать мне.
РЕДАКТИРОВАТЬ # 1: Если я нажму "Нет" для отладки ошибок, страница отобразится так, как мне бы хотелось.