You use
s.Element("a")
, but there are no
a
elements directly in your child1 tag. There are only
a
tags in your
part1
tag.
To access the
a
-tags, you can use
s.Descendants
:
var doc = XElement.Parse(xml);
var ms = doc.Elements("child1").ToList();
var allATags = ms.Select(s => s.Descendants(XName.Get("a")))
.SelectMany(x => x)
.ToList();
ms.Select
returns a collection of collections of XElements here.
SelectMany
merges them all into one, and
ToList
converts it to a list. Now
allATags
contains all
a
-tags within
child1
-tags.