AMP_DOM_Utils::get_content_from_dom PHP Method

get_content_from_dom() public static method

public static get_content_from_dom ( $dom )
    public static function get_content_from_dom($dom)
    {
        // Only want children of the body tag, since we have a subset of HTML.
        $out = '';
        $body = $dom->getElementsByTagName('body')->item(0);
        // AMP elements always need closing tags.
        // To force them, we can't use saveHTML (node support is 5.3+) and LIBXML_NOEMPTYTAG results in issues with self-closing tags like `br` and `hr`.
        // So, we're manually forcing closing tags.
        self::recursive_force_closing_tags($dom, $body);
        foreach ($body->childNodes as $node) {
            $out .= $dom->saveXML($node);
        }
        return $out;
    }

Usage Example

 /**
  * @dataProvider get_data
  */
 public function test_converter($source, $expected)
 {
     $dom = AMP_DOM_Utils::get_dom_from_content($source);
     $sanitizer = new AMP_Video_Sanitizer($dom);
     $sanitizer->sanitize();
     $content = AMP_DOM_Utils::get_content_from_dom($dom);
     $this->assertEquals($expected, $content);
 }
All Usage Examples Of AMP_DOM_Utils::get_content_from_dom