学会放弃

my blog is here

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

migrating your XML transforms to .net 1.1

Before using any sample code published here please read the disclaimer.

'System.Xml.Xsl.XslTransform.Transform(System.Xml.XPath.IXPathNavigable, System.Xml.Xsl.XsltArgumentList, System.IO.TextWriter)' is obsolete: 'You should pass XmlResolver to Transform() method'

My blogs are stored in XML files which are then transformed via XLST to produce HTML or RSS formatted output. When I compiled my transform code under .net 1.1 this warning message appeared.

What do I need to change?

Transforms have changed in v1.1 to add extra security for transforms that use external XLSTs. If you examine the documentation for the Transform() method you will see that the new overloads expect you to pass an instance of an XmlResolver , for example;

public void Transform(XPathNavigator, XsltArgumentList, TextWriter, XmlResolver);

But XmlResolver is an abstract class and thus cannot be created directly. The framework provides a class named XmlUrlResolver, derived from XmlResolver which you can instantiate using new.

In basic XSLT transforms (involving a single XML document) you can pass null as the XmlResolver parameter.

StringWriter sw = new StringWriter(); XslTransform xsl = new XslTransform(); xsl.Load(xslPath); xsl.Transform(xmlDoc,null,sw,null); lblBlogOutput.Text = sw.ToString();












//注意这句话 xsl.Transform(xmlDoc,null,sw,null);
posted on 2006-01-22 16:31  leohuang  阅读(364)  评论(0编辑  收藏  举报