I have an XML and I am using XDocument to traverse the xml document. A
sample document look like the following
<root>
<node1>
<element1 name="n" type="1" />
</node1>
<node2 name='n1' type='2'>
<element2>test</element2>
</node2>
</root>
I would like to find out all the type attribute values for a given
name attribute. How can I do it with a simple linq? I am able to do it
with XmlDocument by writing recursion but there must be a easier way.
I tried the following but it is not giving any result
var result = from c in doc.Elements()
where ((c.Attribute("name") != null) &&
(c.Attribute("type") != null) &&
(c.Attribute("name").Value == 'n'))
select (string)c.Attribute("type").value;
When I debug, I can see only the root element get processed and none
of the other nodes get processed. The same when I applied Elements.
Could someone help?