xpath() public method

Searches for an node in the DOM tree for a given XPath expression.
public xpath ( string $expression, boolean $wrapElement = true ) : Element[] | DOMElement[]
$expression string XPath expression
$wrapElement boolean Returns array of \DiDom\Element if true, otherwise array of \DOMElement
return Element[] | DOMElement[]
Exemplo n.º 1
0
 public function testXpath()
 {
     $html = $this->loadFixture('posts.html');
     $document = new \DOMDocument();
     $document->loadHTML($html);
     $node = $document->getElementsByTagName('body')->item(0);
     $element = new Element($node);
     $elements = $element->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' post ')]");
     $this->assertTrue(is_array($elements));
     $this->assertEquals(3, count($elements));
     foreach ($elements as $element) {
         $this->assertInstanceOf('DiDom\\Element', $element);
     }
 }