在 C# 中对 XPathNodeIterator 的内容进行排序 [英] Sorting an the content of an XPathNodeIterator in C#
问题描述
我有一个我(出于多种原因)无法更改的 DLL.我使用这个程序集来检索一个 XPathNodeIterator
.
I have a DLL which I (for many reasons) cannot change. I use this assembly to retrieve a an XPathNodeIterator
.
我知道我可以使用 XPathNavigator
上的 XPathExpression
对 XML 进行排序以获得 XPathNodeIterator
,问题是我从 XPathNodeIterator
开始code>XPathNodeIterator 有没有办法在之后应用排序?
I know I can sort XML with an XPathExpression
on an XPathNavigator
to get an XPathNodeIterator
, the problem is that I start from the XPathNodeIterator
is there any way to apply a sort afterward?
推荐答案
XPathNodeIterator
是 XPathNavigator
的非泛型 IEnumerable
.因此,如果您使用 .NET 3.5 和 LINQ,则可以执行以下操作:
XPathNodeIterator
is non-generic IEnumerable
of XPathNavigator
. Thus, if you use .NET 3.5 and LINQ, you can do something like this:
IEnumerable<XPathNavigator> sorted =
from XPathNavigator nav in nodeIterator
orderby nav.GetAttribute("@id")
select nav;
这篇关于在 C# 中对 XPathNodeIterator 的内容进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!