tags:

views:

107

answers:

4

For testing purposes I'd like to load an XML file to an XDocument object.

How can I accomplish this? Thanks!

+4  A: 

Use XDocument.Load

Orsol
Thanks! I'll accept this answer when the timer is up.
Serg
+1  A: 

This is a start:

XDocument doc = XDocument.Load("PurchaseOrder.xml");
Console.WriteLine(doc);
Remy
+5  A: 
var xdoc = new XmlDocument();
var filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\kb.xml";

xdoc.Load(filePath);
SKG
+1 Did not know about the '''Environment.SpecialFolder.Desktop''' I assume it will grab the desktop of the currently signed in user too?
J.Hendrix
@J.Hendrix That is correct. This link has more detailed info. http://edn.embarcadero.com/print/32384
SKG
+2  A: 
var path = System.IO.Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), "Filename.xml" );

var xdoc = XDocument.Load( path );
stusmith