使用xpath在两个div之间提取数据

时间:2011-09-17 07:12:32

标签: xml xpath

    <div id="content">
        <div class="sample1">sample text1</div>
        <div class="sample2">
           <span style="float:right">some text2</span>
           <b>some text2</b>
        </div>
        <div class="sample3"> sample text <a href="#">This page</a> 3</div>
        <p>paragraph 1</p>
        <p>paragraph 2</p> 
        <div class="sample4">sample text4</div>
   </div>

我想提取这些类“sample2”和“sample4”之间的数据 输出将显示这个 示例文本3
第1段 第2段

怎么回事?

1 个答案:

答案 0 :(得分:1)

//*[
    preceding-sibling::div[@class = 'sample2'] 
        and following-sibling::div[@class = 'sample4']
]/text()