Xaphann
Xaphann

Reputation: 3677

Reading XML from resource

I am trying to read an XML from a resource but it is return an error. Here is my code;

string s = Properties.Resources.myXMLFile;
XDocument x = XDocument.Load(s);

The error message is as follows;

An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code

Additional information: Illegal characters in path.

Stepping through the code I can see the XML file in the string s. Opening the file both in VS and other XML parsers the file does not give any errors. Why is this error occurring?

Upvotes: 1

Views: 125

Answers (1)

har07
har07

Reputation: 89285

XDocument.Load() expects string containing path to an XML file as argument. If you have the XML content as string, you should use XDocument.Parse() instead :

string s = Properties.Resources.myXMLFile;
XDocument x = XDocument.Parse(s);

Upvotes: 2

Related Questions