【发布时间】:2009-03-31 15:20:51
【问题描述】:
我一直坚持使用我无法控制的 Web 服务,并试图将该服务返回的 XML 解析为标准对象。
部分 XML 结构如下所示
<NO>
<L>Some text here </L>
<L>Some additional text here </L>
<L>Still more text here </L>
</NO>
最后,我希望得到一个类似于 "Some text here Some additional text here Still more text here"
的字符串属性我所拥有的初始通行证如下。我认为我在正确的轨道上,但还没有完全做到:
XElement source = \\Output from the Webservice
List<IndexEntry> result;
result = (from indexentry in source.Elements(entryLevel)
select new IndexEntry()
{
EtiologyCode = indexentry.Element("IE") == null ? null : indexentry.Element("IE").Value,
//some code to set other properties in this object
Note = (from l in indexentry.Elements("NO").Descendants
select l.value) //This is where I stop
// and don't know where to go
}
我知道我可以在该查询的末尾添加一个 ToList() 运算符来返回集合。是否有一种操作或技术可以让我将该集合的串联内联到单个字符串?
如果不清楚,请随时询问更多信息。
谢谢。
【问题讨论】:
标签: c# linq linq-to-xml