QueryPath outerHTML (jQuery for php)

44 views Asked by At

I am using

gravitypdf/querypath (from composer)

I am trying to achieve this function from jQuery/JS in PHP QueryPath:

jQuery("html")[0].outerHTML;

I have tried the following:

echo (string) qp($html, $filter)->parents(":root"); // can't convert document to string

echo qp($html, $filter)->parents(":root")->html(); // returns inner HTML instead of outer HTML

edit, also tried:

echo qp($html, $filter)->parents(":root")->prop('outerHTML'); // prop doesn't exist

echo qp($html, $filter)->parents(":root")->outerHTML; // always returns empty string

// XMLSerializer JS object doesn't exist in PHP...

The issue is that the outerHTML property doesn't exist in queryPath...

please help me solve this...

2

There are 2 answers

0
Luc Laverdure On BEST ANSWER

Found this function in a unit test document:

echo $doc->parents(":root")->get(0)->ownerDocument->saveXML();
1
Travis Heeter On

Have you tried

$('html').prop('outerHTML')

or

$(document).outerHTML

or

new XMLSerializer().serializeToString(document)