0
votes

I am trying this code :

string file =@"C:\Program.xml";
XDocument doc = new XDocument(XElement.Load(file));
XElement root = XElement.Parse(doc);

I get the following error :

the best overloaded method match for has some invalid arguments  

I really need some help...I've been searchig for some hours for a solution.

2

2 Answers

1
votes

XElement.Parse(string s) or XElement.Parse(string s, LoadOptions l) hasn't a overload that accept an XDocument control.
According to this dotnetperls' example you can do this:

XElement xelement = XElement.Load("myFile.xml");
0
votes

XElement.Parse is used to load xml from a string, whereas Load is used to load an xml file - generally you won't need to use both.

I think you may be looking to do something like:

string file = @"C:\Program.xml";
XDocument doc = XDocument.Load(file);
XElement root = doc.Root;
var value = root.Element("foo").Attribute("bar");