This returns node A; is this what you are after?
doc.LoadXml(xml);
foreach (XmlNode node in doc.SelectNodes(@"/doc/item[@Id !
=""1"" and (position() > 1 and position() <= 3)]")) {
Console.WriteLine(node.OuterXml);
}
> xquery is 1-based (not 0-based like C#); nodes 1 & 2 have @Id = "1",
> so are excluded. nodes 3 & 4 (@Id = 2, 3) fail because of the
> position().
Okey but my needs is to get from the result set a range of nodes that start
at the first position, because I don't know by advance how many nodes have
been excluded.
Sam
Marc Gravell - 14 Sep 2007 05:24 GMT
> Okey but my needs is to get from the result set a range of nodes that start
> at the first position, because I don't know by advance how many nodes have
> been excluded.
Oh, that's even easier; for the first only:
@"/doc/item[@Id ! =""1""][1]
For the first 2:
@"/doc/item[@Id ! =""1""][position() <= 2]
Fortunately, position() refers to the position *within the current
working set*, and not the fixed position in the document.
Gotta love it,
Marc