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.

  1. fetch array xpath expression /html/body//h2
  2. iterate on array xpath expression
  3. refer current h2 . , refer first link with

    ./../div[@class='format_text']/p/a[$counter]/img

xpath expression $counter array id.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -