XPath
Like the DOM extension, SimpleXML also supports XPath. Rather than using a separate class for it as the DOM does, the SimpleXMLElement class itself includes a method for it. Where the query() and evaluate() methods of the DOMXPath class return a DOMNodeList instance, the xpath method of SimpleXMLElement instead returns an enumerated array of SimpleXMLElement instances that match the given XPath expression. <?php // Returns all list items from the previous example $elements = $sxe->xpath('//ul[@id="thelist"]/li'); // Outputs "Foo" then "Bar" foreach ($elements as $li) { echo $li, PHP_EOL; } ?> © SimpleXML Extension — Web Scraping >>> Back to TABLE OF CONTENTS <<< | |
Views: 379 | |
Total comments: 0 | |