Rct567/DomQuery

replaceWith

Closed this issue · 4 comments

replaceWith work with DomNode but not work with DomQuery element

Can you give an example? Because it has been tested in:

public function testReplaceWithSelection()

It is specific to my problem. I need to replace root element.
Example:
`use Rct567\DomQuery\DomQuery;

$tpl = new DomQuery("<meta data-wb-role='include' data-wb-src='somefile.php'>");

$tpl->replaceWith(file_get_contents($tpl->attr("data-wb-src"))); // not work

$tpl->find("meta[data-wb-role=include]")->replaceWith(file_get_contents($tpl->find("meta[data-wb-
role=include]")->attr("data-wb-src"))); //not work

echo $tpl->outerHtml();`

Test work with child element, but not work with root element.

Yeh manipulating the root element or its direct children is always troublesome. You could use a 'virtual' root element and get the content of that root element when done. I thought of making DomQuery do this transparently, but I have not yet explored this option and all its possible side effects.