Say I have a string like
string var = "This is a test";
Then I want to use this string to create an instance of XElement like:
XElement element = XElement.Load(var);
var el = new XElement("name", value);
The XElement class is one of the fundamental classes in LINQ to XML. It represents an XML element. The following list shows what you can use this class for: Create elements. Change the content of the element.
Use the XDocument.Parse method to parse the string into an XML Document.
var document = XDocument.Parse("<element>This is a test</element>");
var element = document.Root;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With