如何在c#中将xml文件转换为html [英] how to convert xml file into html in c#
本文介绍了如何在c#中将xml文件转换为html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
XPathDocument myXPathDoc = new XPathDocument(@"C:\aa.xml");
XslTransform myXslTrans = new XslTransform();
myXslTrans.Load(XSLTFile1);
XmlTextWriter myWriter = new XmlTextWriter("result.html", null);
myXslTrans.Transform(myXPathDoc, null, myWriter);
XPathDocument myXPathDoc = new XPathDocument(@"C:\aa.xml");
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load("XSLTFile1.xslt");
XmlTextWriter myWriter = new XmlTextWriter("result.html", null);
myXslTrans.Transform(myXPathDoc, null, myWriter);
推荐答案
试试这个:
Try this:
public void XslTransform(string xsltFileLocation, string xmlDocumentLocation, string DestinationFilepathName)
{
//myXslTrans.Load(xsltFileLocation);
using (MemoryStream ms = new MemoryStream())
{
Stream fs = File.OpenRead(xsltFileLocation);
XPathDocument myXPathDoc = new XPathDocument(xmlDocumentLocation);
XmlTextReader xtr = new XmlTextReader(fs);
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(xtr);
myXslTrans.Transform(myXPathDoc, null, ms);
ms.Flush();
ms.Position = 0;
FileStream fsNew = new FileStream(DestinationFilepathName, FileMode.Create, FileAccess.Write);
byte[] bytes = new byte[ms.Length];
ms.Read(bytes, 0, (int)ms.Length);
fsNew.Write(bytes, 0, bytes.Length);
fsNew.Close();
ms.Close();
}
}
这篇关于如何在c#中将xml文件转换为html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文