public function replaceAll($selector, DOMDocument $document) { $replacement = $this->size() > 0 ? $this->getFirstMatch() : $this->document->createTextNode(''); $c = new QueryPathCssEventHandler($document); $c->find($selector); $temp = $c->getMatches(); foreach ($temp as $item) { $node = $replacement->cloneNode(); $node = $document->importNode($node); $item->parentNode->replaceChild($node, $item); } return qp($document, NULL, $this->options); }
public function testAnyDescendant() { $xml = '<?xml version="1.0" ?> <test> <li id="one"/><li id="two"/><li id="three"> <li id="inner-one" class="foo"> <li id="inner-inner-one" class="foo"/> <il id="inner-inner-two"/> <li id="dont-match-me"/> </li> <li id="inner-two"/> </li> <li id="four"/> <li id="five"/> </test>'; $doc = new DomDocument(); $doc->loadXML($xml); $handler = new QueryPathCssEventHandler($doc); $handler->find('*'); $matches = $handler->getMatches(); $this->assertEquals(11, $matches->count()); $handler = new QueryPathCssEventHandler($doc); $handler->find('*.foo'); $matches = $handler->getMatches(); $this->assertEquals(2, $matches->count()); $this->assertEquals('inner-inner-one', $this->nthMatch($matches, 1)->getAttribute('id')); $handler = new QueryPathCssEventHandler($doc); $handler->find('test > li *.foo'); $matches = $handler->getMatches(); $this->assertEquals(2, $matches->count()); $this->assertEquals('inner-inner-one', $this->nthMatch($matches, 1)->getAttribute('id')); }
public function replaceAll($selector, DOMDocument $document) { $replacement = $this->size() > 0 ? $this->matches[0] : $this->document->createTextNode(''); $c = new QueryPathCssEventHandler($document); $c->find($selector); $temp = $c->getMatches(); foreach ($temp as $item) { $item->parentNode->replaceChild($item, $replacement); } return $this; }