views:

20

answers:

1

The following code returns the error from the For Each loop. I have similar code that does not return the error.

'DisplayTitle' is not a member of 'Sting'

Dim evXML As XDocument = XDocument.Load(Server.MapPath("~/App_Data/event.xml"))

Dim sbEventDetail As New StringBuilder()
Dim summary = _
From sum In evXML.<root>.Elements() _
Select sum...<DisplayTitle>.Value

For Each item In summary
    sbEventDetail.Append("<h4>" & item.DisplayTitle & "</h4>")
Next

The XML:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  <StartTime>2010-03-05T16:00:00</StartTime>
  <EndTime>2010-03-06T02:00:00</EndTime>
  <Duration>10:00:00</Duration>
  <DisplayTitle>MARCH MADNESS</DisplayTitle>
  <Location>565 Main St</Location>
  <IsAllDay>False</IsAllDay>
  <Recurrence>
    <OriginatingTimeZone>Eastern Standard Time</OriginatingTimeZone>
    <RecurrenceType>0</RecurrenceType>
    <RecurrenceEndDate>9999-12-31T23:59:59</RecurrenceEndDate>
  </Recurrence>
  <IsVariance>False</IsVariance>
  <IsCancelled>False</IsCancelled>
  <OriginalStart>0001-01-01T00:00:00</OriginalStart>
</root>
+2  A: 

Look at what you're selecting:

Select sum...<DisplayTitle>.Value

The Value property returns a string - so the type of the summary variable is IEnumerable(Of String).

You probably just need:

For Each item In summary
    sbEventDetail.Append("<h4>" & item & "</h4>")
Next

... assuming you don't need any HTML-escaping, mind you.

Jon Skeet
Thank you John!
mmcglynn