I am using Symfony Crawler component to parse html like this:
<div> //first level div
<div>1</div> //sub div
<div>2</div>
<div>
<div></div> // more levels and empty divs possible
</div>
</div>
<div>
<div>3</div>
<div>4</div>
</div>
Values 1 2 3 4 may vary, or even not exist in an empty div, but also div could contain subDivs etc. I'm stuck at phase of selecting first level divs to process them. Xpath request return me first level divs and also subdivs
$crawler = new Crawler($html);
foreach ($crawler->filterXPath('//div') as $domElement) {
var_dump($domElement->textContent);
}
returns
string(2) "12"
string(1) "1"
string(1) "2"
string(2) "34"
string(1) "3"
string(1) "4"
How should Xpath request look like to prevent processing of subElements?
UPD:
actual trouble DOM scheme
<div> //first level div
<div>1</div> //sub div
<div>2</div>
</div>
<div>
<div>3</div>
<div>4
<div>5</div>
<a>6</a>
</div>
</div>
This DOM tree should be processed by first level divs and depending on existence of <a>
tag makes some logic.