我在理解childNodes中存储的内容时遇到了一些麻烦.理想情况下,我想在每个子节点上做另一个xquery,但似乎无法直截了当.这是我的情景:
数据:
数据:
<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>
和代码:
$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? }
对于“某事物”的每个元素(即$n),我想要访问两段文本和href的值.我尝试使用childNode和另一个xquery,但无法获得任何工作.任何帮助将不胜感激!