【发布时间】:2016-12-06 15:11:43
【问题描述】:
我尝试使用将遍历 xml 文档的 LINQ 查询。但是我想使用 OR 语句或 string.toLower() 来确保它总是能得到它需要的数据
我目前有:
// read all <item> tags and put the in an array.
XDocument xml = XDocument.Parse(xmlData);
var newItems = (from story in xml.Descendants("item")
select new Feed
{
Title = ((string) story.Element("title")),
Link = ((string) story.Element("link")),
Description = ((string) story.Element("description")),
PublishDate = ((string) story.Element("pubDate")),
}
).Take(20).ToList();
我还想改变什么:
- (例如)
Title = ((string)story.Element("title"))需要不区分大小写。 -
from story in xml.Descendants("item") select new Feed需要在项目和条目中搜索(均不区分大小写)。
PS:当我正在遍历 RSS 文档时,我无法直接访问 XML 文档。
感谢您的意见。
【问题讨论】:
-
"
((string)story.Element("title"))需要不区分大小写" 这是否意味着您的 xml 中有title和Title?我不明白您所说的搜索不区分大小写是什么意思。 -
@HimBromBeere,无论是标题还是标题,它都会返回相同的结果。