I am importing some html into a dom document ans use xpath to extract the html part I am interested in. See below:
$dom = new DOMDocument();
@$dom->loadHTML(‘$myHtmlFileHere’);
$xpath_dom_doc = new DomXPath($dom);
$dom_object = $dom_document->query(‘myPathHere’);
Here below the html structure “returned”:
<div>GROUP A</div>
<span>aaa</span>
<span>zzz awesome</span>
<span>eee</span>
<div>GROUP B</div>
<span>fff</span>
<div>GROUP C</div>
<span>zzz</span>
<span>uuu</span>
<span>iii</span>
<span>rrr</span>
As you see I have categories (GROUP A, GROUP B and GROUP C). In the spans below each category I have information related to the category. What I would like is send to a db the span content with the related category. The problem that I am confronted to is that the div tag of the category is not wrapping the spans. So I do not see how I can manage that. hope someone can help. thank you in advance. Cheers. Marc
What about the
following-siblingxpath function? You should be careful, though, and only select the siblings up to a nextdiv.For example, tested with xsh2: