codeigniter,查看模板字符串到DomDocument操作

I have a php file in application\views\article.php

article.php content:

<!DOCTYPE html>
<html prefix='og: http://ogp.me/ns#'>
<head>
    <title>test</title>
</head>
<body>
<div> test div1 </div>
<div> test div2 </div>
</body>
</html>

When I use $this->load->view() to load article.php template and use DomDocument to get dom.

$html=$this->load->view('article','',TRUE);
$doc = new DomDocument;
$doc->loadHTML($html);      
echo $doc->saveXML($doc->getElementsByTagName('div')->item(0));
// or echo $doc->saveXML();

have the error message: Message: DOMDocument::loadHTML(): Unexpected end tag : meta in Entity, line: 4

but whe I use this:

$html='<!DOCTYPE html>
    <html prefix=\'og: http://ogp.me/ns#\'>
    <head>
        <title>test</title>
    </head>
    <body>
    <div>   test div1 </div>
    <div> test div2 </div>
    <p>Directory </p>
    </body>
    </html>';

  $doc->loadHTML($html);         
  echo $doc->saveXML($doc->getElementsByTagName('div')->item(0));
  // or echo $doc->saveXML();

this is success.

gettype($html) to two methods of $html, both are strings.

Try hide the warning with

libxml_use_internal_errors(true);

Or:

@$doc->loadHTML($html);

The warning is because the HTML returned by $this->load->view('article','',TRUE); is invalid, loadHTML() resolve this but show the warnings.

Manual