src/Drupal/Component/Utility/Html.php
public static function serialize(\DOMDocument $document) {
    $body_node = $document->getElementsByTagName('body')->item(0);
    $html = '';

    if ($body_node !== NULL) {
      foreach ($body_node->getElementsByTagName('script') as $node) {
        static::escapeCdataElement($node);
      }
      foreach ($body_node->getElementsByTagName('style') as $node) {
        static::escapeCdataElement($node, '/*', '*/');
      }
      foreach ($body_node->childNodes as $node) {
        $html .= $document->saveXML($node);
      }
    }
    return $html;
  }
public static function serialize(\DOMDocument $document) {
    $body_node = $document->getElementsByTagName('body')->item(0);
    $html = '';

    if ($body_node !== NULL) {
      foreach ($body_node->getElementsByTagName('script') as $node) {
        static::escapeCdataElement($node);
      }
      foreach ($body_node->getElementsByTagName('style') as $node) {
        static::escapeCdataElement($node, '/*', '*/');
      }
      foreach ($body_node->childNodes as $node) {
        $html .= $document->saveXML($node);
      }
    }
    return $html;
  }
public static function serialize ( \ DOMDocument $ document ) { $ body_node = $ document -> getElementsByTagName ( 'body' ) -> item ( 0 ) ; $ html = '' ; if ( $ body_node !== NULL ) { foreach ( $ body_node -> getElementsByTagName ( 'script' ) as $ node ) { static :: escapeCdataElement ( $ node ) ; } foreach ( $ body_node -> getElementsByTagName ( 'style' ) as $ node ) { static :: escapeCdataElement ( $ node , '/*' , '*/' ) ; } foreach ( $ body_node -> childNodes as $ node ) { $ html .= $ document -> saveXML ( $ node ) ; } } return $ html ; }
Converts the body of a \DOMDocument back to an HTML snippet.

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

@param \DOMDocument $document
A \DOMDocument object to serialize, only the tags below the first <body>
node will be converted.

@return string
A valid (X)HTML snippet, as a string.
Converts the body of a \ DOMDocument back to an HTML snippet .