How to get a value of XElement
without getting child elements?
An example:
someValue
You can do it slightly more simply than using Descendants
- the Nodes
method only returns the direct child nodes:
XElement element = XElement.Parse(
@"somevalue1 2 ");
var firstTextValue = element.Nodes().OfType().First().Value;
Note that this will work even in the case where the child elements came before the text node, like this:
XElement element = XElement.Parse(
@"1 2 some value ");
var firstTextValue = element.Nodes().OfType().First().Value;