LINQ 到 XML 错误“不是“String”的成员”
以下代码返回 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>
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">
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看您选择的内容:
Value 属性返回一个字符串 - 因此
summary
变量的类型为IEnumerable(Of String)
。您可能只需要:
...假设您不需要任何 HTML 转义,请注意。
Look at what you're selecting:
The Value property returns a string - so the type of the
summary
variable isIEnumerable(Of String)
.You probably just need:
... assuming you don't need any HTML-escaping, mind you.