以下代码从For Each循环返回错误。我有类似的代码,不会返回错误。
'DisplayTitle'不是'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
XML:
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<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>
答案 0 :(得分:2)
看看你在选择什么:
Select sum...<DisplayTitle>.Value
Value属性返回一个字符串 - 因此summary
变量的类型为IEnumerable(Of String)
。
你可能只需要:
For Each item In summary
sbEventDetail.Append("<h4>" & item & "</h4>")
Next
...假设您不需要任何HTML转义,请注意。