DomQuery icon indicating copy to clipboard operation
DomQuery copied to clipboard

replaceWith

Open aikianapa opened this issue 4 years ago • 3 comments

replaceWith work with DomNode but not work with DomQuery element

aikianapa avatar Sep 16 '19 11:09 aikianapa

Can you give an example? Because it has been tested in: https://github.com/Rct567/DomQuery/blob/15208bd61f0b87d3befa795a38e5b47a3dbebb97/tests/Rct567/DomQuery/Tests/DomQueryManipulationTest.php#L372

Rct567 avatar Oct 18 '19 14:10 Rct567

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();`

aikianapa avatar Oct 21 '19 08:10 aikianapa

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

aikianapa avatar Nov 02 '19 09:11 aikianapa

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.

Rct567 avatar Sep 15 '23 21:09 Rct567