DomQuery
DomQuery copied to clipboard
replaceWith
replaceWith work with DomNode but not work with DomQuery element
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
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.