VJamie
VJamie

Reputation: 636

XPath select all child nodes of child-div except for specific class

I've been trying for a couple of hours and can't get my XPath to select the right text. Here's the structure:

<!-- (some divs that don't need to be selected) -->
<div class="main">
  <div>
    <div>
      <div class="select">
        <div class="child">
          <div class="divwithtext">
          </div>
        </div>
        <div class="child">
          <div class="divwithtext">
          </div>
        </div>
        <div class="child">
          <div class="divwithtext">
          </div>
        </div>
        <div class="dontselect">
          <div class="divwithtext">
          </div>
        </div>
      <div/>
    </div>
  </div>
</div>

Basically I want to select all the children of class="select" which is a child of class="main", but I don't need the text of class="dontselect".

Note: I am using XPath 1.0 due to php DOMXPath only supporting 1.0.

Edit:

Problem was my PHP code not returning all results that XPath gave me.

Upvotes: 3

Views: 2346

Answers (1)

har07
har07

Reputation: 89325

One possible way :

//div[@class='main']//div[@class='select']/div[not(@class='dontselect')]

Upvotes: 3

Related Questions