php - Retrieving (relating) two separate tags/attributes using a single XPath query? -
i xpathing domdocument file have. general pattern of domdocument follows:
<h2> title info </h2> <div> .... </div> <p> ...</p> <div class = format_text> <p> <a href= "http://link..."><img src = "http://sourceofimageonline.com"></a> </p> </div> <h2> 2nd title</h2> <div> .... </div> <p> ...</p> <div class = format_text> <p> <a href= "http://link..."><img src = "http://sourceofimageonline.com"></img></a> <a href = "http://linkanother.."><img src = "http://sourceofimageonline.com"</img></a> </p> </div> the key return titles , src attribute images hyperlinks. essentially, render :
title 1 img uri 1 title 2 img uri 2 img uri 3 ... ..
now titles can retrieved using
domdocument->getelementsbytagnames('h2') and img src retrieved xpath query:
//div[@class = "format_text"]/p/a/img/@src this returns information need. however, being challenged trying img src's relate titles fall under. since retrieved independently, unable comprehend kind of xpath query need execute retrieve both such above constraint satisfied.
- fetch array xpath expression
/html/body//h2 - iterate on array xpath expression
refer current
h2., refer first link with./../div[@class='format_text']/p/a[$counter]/img
xpath expression $counter array id.
Comments
Post a Comment