19

I have a System.Web.UI.WebControls.Xml control (Xml1) in a webforms app that I have upgraded from .NET 2.0 to .NET 4.0

I am getting two warnings from the code-behind page that I'd like to do something about.

... 
Dim ds As DataSet = app.GetObjects
Dim xmlDoc As New System.Xml.XmlDataDocument(ds)
Xml1.Document = xmlDoc
Xml1.TransformSource = "~/xslt/admin_objectslist.xslt"
...

From the second line I get the warning:

'System.Xml.XmlDataDocument' is obsolete: 'XmlDataDocument class will be removed in a future release.'.

And from the third line I get the warning:

'Public Property Document As System.Xml.XmlDocument' is obsolete: 'The recommended alternative is the XPathNavigator property. Create a System.Xml.XPath.XPathDocument and call CreateNavigator() to create an XPathNavigator.

What is the recommended .NET 4.0 replacement for this?

Nick
  • 4,115
  • 10
  • 45
  • 57

2 Answers2

29

ds.I ran into this problem with 3.5 as well. Here is what I came up with:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(ds.GetXml());
xml1.XPathNavigator = xmlDoc.CreateNavigator();                
xml1.TransformSource = @"~/XSLT/LogEntryTransform.xslt";

Hope it helps.

Ben
  • 546
  • 5
  • 11
0

Use Linq2XML - it's way more powerful than any of the other XML tools.... allows you to query and create/read/update/delete (CRUD) the XML just like you would a dataset or other strongly typed data source.

Once you get started with Linq you'll never go back to the old ways... it absolutely rocks!

H. Brandsmeier
  • 957
  • 5
  • 19
Mike
  • 17
  • 2
  • 6
    While you're right that Linq was the MS approved upgrade for dealing with xml, your answer needs code to show how to do what you're talking about in order to be complete. – TheAtomicOption Jun 14 '19 at 18:14