I have the following code that I need to migrate from VS 2003 (.Net 1.1) to VS 2008 (.Net 2+)
but I get compilation error -
System.Xml.Xsl.XslTransform' is obsolete: This class has been deprecated.
I probably need to use System.Xml.Xsl.XslCompiledTransform instead.
but I do not find the matching Load() and Transform() overload versions that I can use with all the parameters of my original code.
in MSDN [How to: Migrate Your XslTransform Code] I only found some simpler cases.
http://msdn.microsoft.com/en-us/library/aa983475%28VS.80%29.aspx
but in my code I see some remarks that hints that the added parameters were used to avoid exceptions, so I prefer to use these parameters.
Can someone please help migrating this code?
Thanks,
Atara
' ----------------------------------------------------------------------
' VS 2003 code:
' ----------------------------------------------------------------------
. . .
Dim myXslDoc As Xml.XmlDocument
' ----------------------------------------------------------------------
Public Sub mcSetParameters(ByVal srcFileName As String)
' ----------------------------------------------------------------------
Me.myXslDoc = New Xml.XmlDocument
Me.myXslDoc.Load(srcFileName)
End Sub
' ----------------------------------------------------------------------
Public Sub mcSetHtml()
' ----------------------------------------------------------------------
Dim oXPathNav As System.Xml.XPath.XPathNavigator = xmlDoc.DocumentElement.CreateNavigator()
Dim sbContent As New System.Text.StringBuilder
Dim swContent As New System.IO.StringWriter(sbContent)
Dim args As New System.Xml.Xsl.XsltArgumentList
args.AddParam("paramName1", "", paramVal1.ToString)
args.AddParam("paramName2", "", paramVal2.ToString)
Try
' Try to avoid "Invalid site" exception, by using XmlUrlResolver and Evidence.
' If the XSLT stylesheet . . . comes from a code base that you trust, Then use Me.GetType().Assembly.Evidence()
Dim resolver As System.Xml.XmlUrlResolver = New System.Xml.XmlUrlResolver
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim xslt As System.Xml.Xsl.XslTransform = New System.Xml.Xsl.XslTransform
xslt.Load(Me.myXslDoc, resolver, Me.GetType().Assembly.Evidence())
xslt.Transform(oXPathNav, args, swContent, Nothing)
Catch ex As Exception
Debug.WriteLine("Exception: {0}", ex.ToString())
End Try
DoSomething(sbContent.ToString())
End Sub
' ----------------------------------------------------------------------