function filter_dom_serialize

Converts a DOM object back to an HTML snippet.

The function serializes the body part of a DOMDocument back to an XHTML snippet. The resulting XHTML snippet will be properly formatted to be compatible with HTML user agents.

Parameters

$dom_document: A DOMDocument object to serialize, only the tags below the first <body> node will be converted.

Return value

A valid (X)HTML snippet, as a string.

3 calls to filter_dom_serialize()
_filter_html in drupal/core/modules/filter/filter.module
Provides filtering of input into accepted HTML.
_filter_htmlcorrector in drupal/core/modules/filter/filter.module
Scans the input and makes sure that HTML tags are properly closed.
_filter_html_image_secure_process in drupal/core/modules/filter/filter.module
Process callback for local image filter.

File

drupal/core/modules/filter/filter.module, line 950
Framework for handling the filtering of content.

Code

function filter_dom_serialize($dom_document) {
  $body_node = $dom_document
    ->getElementsByTagName('body')
    ->item(0);
  $body_content = '';
  foreach ($body_node
    ->getElementsByTagName('script') as $node) {
    filter_dom_serialize_escape_cdata_element($dom_document, $node);
  }
  foreach ($body_node
    ->getElementsByTagName('style') as $node) {
    filter_dom_serialize_escape_cdata_element($dom_document, $node, '/*', '*/');
  }
  foreach ($body_node->childNodes as $child_node) {
    $body_content .= $dom_document
      ->saveXML($child_node);
  }
  return $body_content;
}