我有一个 linq to xml 查询,它返回 2 个节点。我正在尝试遍历这些节点并替换它们的内容。但是,添加到 XDocument 的内容包含符合我的查询条件的节点。
protected internal virtual void AddLinkDocument(XDocument content, TaskRequest request)
{
var links = content.Descendants("some.link").Where(tag => tag.Attribute("document-href") != null);
foreach (XElement link in links) //first time through there are 2 links found
{
//do some stuff
link.ReplaceNodes(inlineContent); // after content is added, "links" now in foreach now has many new links found
}
}
为什么每次通过foreach动态更新集合“链接”?
谢谢您的帮助!