views:

25

answers:

2

My xml looks like this

<Element> text <B>text<B></Element>

Unknown number of B tags or tags even of a different name.

How do i get the text from these? so it would be like this

text text

using linq to xml

+1  A: 

You could do the following assuming XElement was pointing to the Element tag

var root = GetRoot();
var text = root.Elements("B").Select(x => x.Value);
JaredPar
To include tags with a different name, you'd call `root.Elements()` without a parameter.
StriplingWarrior
A: 

As you need any children not just the "B"s if root is your Element tag as as XElement

var text = string.Empty;
root.DescendentsAndSelf().Select(x => text += x.Value);

Kindness,

Dan

Daniel Elliott