I want to get the index of a node using XPath, but I’d love to do it in a single line. I want the int that I’m storing to double as proof of existence of the node, and the position of the FIRST occurrence of a matching node.
What I have now does what I want, but it matches the LAST occurrence of a matching node instead of the first. Can I alter this to get me the first one?
int base_Schemes = xmlWebConfig.SelectNodes("/configuration/Security/Authentication/schemes/scheme[@type='ssoscheme, sso']/preceding-sibling::scheme").Count;
Are you looking for the
position()function?Try
/configuration / Security / Authentication / schemes [@type = 'ssoscheme, sso'] / preceding-sibling::scheme / position().