XslTransform.Transform将结果输出到字符串里的方法
程序员文章站
2023-11-11 20:41:40
xsltransform.transform 方法将结果输出到字符串里有2中办法: 通过system.io.memorystream类来实现。&nbs...
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);
通过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);