In .NET, how do I read the text content from an XElement?
For example, from the XElement
XElement.Parse("<tag>Alice & Bob<other>cat</other></tag>")
I would like the string 'Alice & Bob'
I tried element.Value
but that returns 'Alice & Bobcat' :(
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.
XElement element = XElement. Load(var); c#
XElement t = XElement.Parse("<tag>Alice & Bob<other>cat</other></tag>");
string s = (t.FirstNode as XText).Value;
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