c# - Select Table Rows by Grouping them Adjacent to each Other using XPath -
i not clear how express problem correctly in question forgive me if not able convey problem. have following data.
<tr class="header">random value 1</tr> <tr class="item">1</tr> <tr class="item">2</tr> <tr class="item">3</tr> <tr class="header">random value 2</tr> <tr class="item">4</tr> <tr class="item">5</tr> <tr class="item">6</tr> <tr class="header">random value 3</tr> <tr class="item">7</tr> <tr class="item">8</tr> <tr class="item">9</tr> what want acheive want select class header. have achieved using following line of code,
htmlnodecollection headernodes = doc.documentnode.selectnodes("//tr[@class='header']"); now have header rows in collection. loop through header nodes , want table rows adjacent respective header rows.
foreach (htmlnode node in headernodes) { htmlnodecollection itemnodes = ??? } my question should write here header row text "random value 1" item rows 1,2 , 3. header row text "random value 2" item row 4,5 , 6 , on.
i'm not sure htmlnodecollection is, if use normal xpath , selectnodes (which return xmlnodecollection) find elements you're looking node.nextsibling. so, loop like:
foreach (xmlnode node in headernodes) { string entry = node.nextsibling.innerxml; }
Comments
Post a Comment