I’m working on a little project and trying to figure out if I can load an XDocument from a string. XDocument. The text given to Load() appears to be a path to a physical XML file.
I’d like to skip over the phase of creating the physical XML file and go right to populating the XDocument.
Asked by StevenMcD
For this, you can use XDocument.Parse.
Answered by Ronald Wildenberg
XDocument is an option. Instead of Load, use Parse(string) (string).
Answered by Samuel
How about this…?
TextReader tr = new StringReader("<Root>Content</Root>"); XDocument doc = XDocument.Load(tr); Console.WriteLine(doc);
This was derived from the XDocument MSDN documentation. This is where you’ll find the load…
Answered by Martin Peck
Take a look at the Parse method.
Answered by bruno conde
Post is based on https://stackoverflow.com/questions/747554/populate-xdocument-from-string