views:

17

answers:

1

Given the following XML, I would like to return all eventtitles where the eventtype id = 23. My current query only looks at the first eventtype, so returns the wrong result.

    <event>
      <eventtitle>Garrison Keillor</eventtitle>
      <eventtypes>
        <eventtype id="24"/>
        <eventtype id="23"/>
      </eventtypes>
    </event>
    <event>
      <eventtitle>Joe Krown Trio featuring Walter Wolfman Washington</eventtitle>
      <eventtypes>
        <eventtype id="23"/>
      </eventtypes>
    </event>

LINQ query:

Dim query = _
From c In calXML...<event> _
Where c...<eventtypes>.<eventtype>.@id = "23" _
Select c.<eventtitle>.Value, c.<eventlocation>.Value


For Each item In query
    Response.Write("<h3>" & item.eventtitle & "</h3>")
    Response.Write(item.eventlocation & "<br />")
Next
+1  A: 

You need to call Any, like this:

Dim query = _ 
From c In calXML...<event> _ 
Where c.<eventtypes>.<eventtype>.Any(Function(t) t.@id = "23") _ 
Select c.<eventtitle>.Value, c.<eventlocation>.Value 
SLaks
What is the significance of the Function?
mmcglynn
It's a Lambda Expression. http://msdn.microsoft.com/en-us/library/bb531253.aspx
SLaks