Xpath to search descendents of a node

Impaicaratcap

New Member
I have the following c# method, that performs some operation on all nodes reachable from refNode, through xpath\[code\]void foo(XmlNode refNode, string xpath){ XmlNodeList list=refNode.SelectNodes(xpath); //perform operation on each element of the list}\[/code\]One of the input xml that i'm getting is:\[code\]<A> <B>*** <C> <B>One</B> </C> <B> <B>Two</B> </B> </B> <B>...</B> <B>...</B></A>\[/code\]where i need to select a refNode \[code\]<B>\[/code\] (marked \[code\]***\[/code\]) and pass it to foo() with an xpath that selects all descendent \[code\]<B>\[/code\] nodes of refNode, but not nested inside any other \[code\]<B>\[/code\] nodefor example in the given input the result should contain:\[code\]1. <B>One</B>2. <B><B>Two</B></B>\[/code\]I have tried .//B which gives me 3 results and .//B[not(ancesotr::B)] which returns 0 results.What Xpath should I use to get the desired result?
 
Back
Top