具有条件的xpath特定选择

时间:2011-11-11 13:12:25

标签: xpath conditional-statements

这可能很简单,但我想在<div class="rc-box-citations-body">内选择一切必须属于<div class="definitionBox" id="meaning-1-1">的条件,从而唯一地识别它。我怎么能用xpath做到这一点?感谢。

 <div class="definitionIndent">
  <div class="definitionNumber">1.a</div>
  <div class="definitionIndent">
    <div class="definitionBox" id="meaning-1-1">
      <span class="textmedium">
        <span class="stampNoBorder">text</span>
        <span class="definition">text</span>
      </span>
    </div>
    <div class="definitionBox">
      <div class="rc-box-citations">
        <div class="rc-box-citations-top">
          <span class="rc-citations-north-west">&#160;</span>
          <span class="rc-citations-north-east">&#160;</span>
        </div>
        <div class="rc-box-citations-body"><span class="citat">text</span> <a class="sourcepop" href="javascript:void(0);"><span class="source">text</span><span class="popup">text</span></a></div>
        <div class="rc-box-citations-bot">
          <span class="rc-citations-south-west">&#160;</span>
          <span class="rc-citations-south-east">&#160;</span>
        </div>
      </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

如果我稍微修改你的xml,并在必须属于的条件下取来表示的后代 ....那么这个xpath工作< / p>

//div[@class='definitionBox'][@id='meaning-1-2']//div[@class='rc-box-citations-body']

XML

<?xml version="1.0" encoding="utf-16"?>
<div class="definitionIndent">
  <div class="definitionNumber">1.a</div>
  <div class="definitionIndent">
    <div class="definitionBox" id="meaning-1-1">
      <span class="textmedium">
        <span class="stampNoBorder">text</span>
        <span class="definition">text</span>
      </span>
    </div>
    <div class="definitionBox" id="meaning-1-2">
      <div class="rc-box-citations">
        <div class="rc-box-citations-top">
          <span class="rc-citations-north-west"></span>
          <span class="rc-citations-north-east"></span>
        </div>
        <div class="rc-box-citations-body">
          <span class="citation">text</span>
          <a class="sourcepop" href="javascript:void(0);">
            <span class="source">text</span>
            <span class="popup">text</span>
          </a>
        </div>
        <div class="rc-box-citations-bot">
          <span class="rc-citations-south-west"></span>
          <span class="rc-citations-south-east"></span>
        </div>
      </div>
    </div>
  </div>
</div>

我使用的工具是XPathVisualizer:

enter image description here