I'm working on a little something and I am trying to figure out whether I can load an XDocument from a string. XDocument.Load()
seems to take the string passed to it as a path to a physical XML file.
I want to try and bypass the step of first having to create the physical XML file and jump straight to populating the XDocument.
Any ideas?
This question is related to
c#
xml
c#-3.0
linq-to-xml
How about this...?
TextReader tr = new StringReader("<Root>Content</Root>");
XDocument doc = XDocument.Load(tr);
Console.WriteLine(doc);
This was taken from the MSDN docs for XDocument.Load, found here...
Try the Parse method.
You can use XDocument.Parse(string)
instead of Load(string)
.
Source: Stackoverflow.com