linq to xml enumerating over descendants
Posted
by
gh9
on Stack Overflow
See other posts from Stack Overflow
or by gh9
Published on 2011-01-13T15:13:08Z
Indexed on
2011/01/13
15:53 UTC
Read the original article
Hit count: 210
vb
|linq-to-xml
Hi trying to write a simple linq query from a tutorial I read. But i cannot seem to get it to work. I am trying to display both the address in the attached xml document, but can only display the first one. Can someone help me figure out why both aren't being printed. Thank you very much
<?xml version="1.0" encoding="utf-8" ?>
<Emails>
<Email group="FooBar">
<Subject>Test subject</Subject>
<Content>Test Content</Content>
<EmailTo>
<Address>[email protected]</Address>
<Address>[email protected]</Address>
</EmailTo>
</Email>
</Emails>
Dim steve = (From email In emailList.Descendants("Email") _
Where (email.Attribute("group").Value.Equals("FooBar")) _
Select content = email.Element("EmailTo").Descendants("Address")).ToList()
If Not steve Is Nothing Then
For Each addr In steve
Console.WriteLine(addr.Value)
Next
Console.ReadLine()
End If
© Stack Overflow or respective owner