XslTransform.Transform 方法將結果輸出到字符串裡有2中辦法:
通過System.IO.MemoryStream類來實現。
通過System.Text.StringBuilder類來實現。
下面是具體的實現方法:
復制代碼 代碼如下:
System.Xml.Xsl.XslTransform RssXslt = new System.Xml.Xsl.XslTransform();
System.Xml.XmlDocument RssXml = new System.Xml.XmlDocument();
RssXslt.Load(Server.MapPath("RssReader.xslt"));
RssXml.Load(Server.MapPath("Rss.xml"));
System.IO.MemoryStream t = new System.IO.MemoryStream();
RssXslt.Transform(RssXml,null,t,null);
string resultString = System.Text.UTF8Encoding.UTF8.GetString(t.ToArray());
Response.Write(resultString);
System.Xml.Xsl.XslTransform RssXslt = new System.Xml.Xsl.XslTransform();
System.Xml.XmlDocument RssXml = new System.Xml.XmlDocument();
RssXslt.Load(Server.MapPath("RssReader.xslt"));
RssXml.Load(Server.MapPath("Rss.xml"));
System.Text.StringBuilder t = new System.Text.StringBuilder();
RssXslt.Transform(RssXml,null,new System.IO.StringWriter(t),null);
string resultString = t.ToString();
Response.Write(resultString);