I am having trouble understanding what exactly is stored in childNodes. Ideally, I would like to do another xquery on each of the child nodes, but it might not seem like it's straightforward. Here is my scenario: Data:
<div class="something"> <h3> <a href="link1.html">Link text 1</a> </h3> <div class"somethingelse">Something else text 1</div> </div> <div class="something"> <h3> <a href="link2.html">Link text 2</a> </h3> <div class"somethingelse">Something else text 2</div> </div> <div class="something"> <h3> <a href="link3.html">Link text 3</a> </h3> <div class"somethingelse">Something else text 3</div> </div>
And the code:
$html = new DOMDocument(); $html->loadHtmlFile($local_file); $xpath = new DOMXPath( $html ); $nodelist = $xpath->query( "//div[@class='something']"); foreach ($nodelist as $n) { Can I run another query here? }
For each "something" element (i.e. $ n) I want to access the values of the two parts of the text and href. I tried using childNode and another xquery but couldn't get it working. Any help would be greatly appreciated!
Bryan source share