Automattic\WooCommerce\EmailEditor\Integrations\Utils

Dom_Document_Helper::get_root_html │ public │ WC 1.0

Serializes every top-level node of the loaded fragment back to HTML.

The document is loaded with LIBXML_HTML_NOIMPLIED (no implicit html/body wrapper), so the top-level nodes are the fragment's own roots. Useful for reading back what remains after elements have been removed.

Method of the class: Dom_Document_Helper{}

No Hooks.

Returns

string.

Usage

$Dom_Document_Helper = new Dom_Document_Helper();
$Dom_Document_Helper->get_root_html(): string;

Dom_Document_Helper::get_root_html() code WC 11.1.2

public function get_root_html(): string {
	$html = '';
	foreach ( $this->dom->childNodes as $child ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
		// Skip the `<?xml encoding="UTF-8">` processing instruction that load_html() prepends to
		// force UTF-8; serializing it back would corrupt callers (e.g. strip_tags treats the
		// unterminated `<?` as a tag and swallows the rest of the string).
		if ( XML_PI_NODE === $child->nodeType ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
			continue;
		}
		$html .= (string) $this->dom->saveHTML( $child );
	}
	return $html;
}