开发者

XslTransform class is deprecated after .NET conversion

I had XslTransform in an old program, and after converting the code the the .NET F 3.5, the compiler said that XslTransform is deprecated and replaced by XslCompiledTransform.

This is the old code :

XslTransform xslt = new XslTransf开发者_C百科orm();
xslt.Load(xslTemplate);
xslt.Transform(xPathNav, null, fileStream, null);

I've changed the code to look like this :

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(xslTemplate); 
xslt.Transform(xPathNav, fileStream);

And now I get :

cannot convert from 'System.IO.FileStream' to 'System.Xml.XmlWriter'

I tried to correct that by adding doing this :

XPathDocument doc = new XPathDocument(fileStream);
XmlWriter writer = XmlWriter.Create(Console.Out, xslt.OutputSettings);
xslt.Transform(doc, writer);

I don't get errors anymore, but I the code is not doing XML transformation.

Any ideas ?

Thanks.


I think

XslTransform xslt = new XslTransform();
xslt.Load(xslTemplate);
xslt.Transform(xPathNav, null, fileStream, null);

can be written as follows with XslCompiledTransform

XslTransform xslt = new XslCompiledTransform();
xslt.Load(xslTemplate);
xslt.Transform(xPathNav, null, fileStream);


MSDN actually has a full article on Migrating From XslTransform to XslCompiledTransform


In the first couple of code snippets, you seem to be using fileStream for output and xPathNav for input.

But in the last snippet, you're using fileStream (via doc) for input.

Did you really change fileStream to be your input document, or is this a mistake?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜