Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert from string to XElement object

Tags:

c#

xml

xelement

I have a string like this: "<Root><Child>Hey</Child></Root>"

How can I convert this to an XElement Object?

like image 986
realn Avatar asked Oct 21 '11 09:10

realn


People also ask

How do you make XElement?

var el = new XElement("name", value);

What is XElement?

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.


1 Answers

Use XElement.Parse method like below

XElement xmlTree = XElement.Parse("<Root><Child>Hey</Child></Root>"); Console.WriteLine(xmlTree); 
like image 93
Sai Kalyan Kumar Akshinthala Avatar answered Sep 27 '22 18:09

Sai Kalyan Kumar Akshinthala