2012-12-11 102 views
1

我使用HtmlAgilityPack來解析html頁面。我想選擇一個標籤h3的集合,然後遍歷它,並且對於每個h3元素,我想選擇它旁邊的一個元素。這裏是我的示例HTML:選擇當前元素旁邊的元素HtmlAgilityPack

<h3>Somthing here</h3> 
<ul>list of something</ul> 

<h3>Somthing here</h3> 
<ul>list of something</ul> 

<h3>Somthing here</h3> 
<ul>list of something</ul> 

<h3>Somthing here</h3> 
<ul>list of something</ul> 

<h3>Somthing here</h3> 
<ul>list of something</ul> 

我知道如何選擇H3的集合,但我沒有任何想法如何選擇UL旁邊的每個

回答

2

如果當前節點爲h3,使用的XPath :

following-sibling::ul[1] 

它選擇1 STul兄弟節點。

+0

你的意思是:h3Node.selectSingleNode(「following-sibling :: ul [1]」)? –