Bug #66712 [Com]: Using LIBXML_HTML_NOIMPLIED on DomDocument::loadHTML() gives unexpected results

From: Date: Mon, 09 Nov 2015 14:47:03 +0000
Subject: Bug #66712 [Com]: Using LIBXML_HTML_NOIMPLIED on DomDocument::loadHTML() gives unexpected results
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197131@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66712&edit=1

 ID:                 66712
 Comment by:         dlundgren at syberisle dot net
 Reported by:        chanson at mesd dot k12 dot or dot us
 Summary:            Using LIBXML_HTML_NOIMPLIED on
                     DomDocument::loadHTML() gives unexpected results
 Status:             Verified
 Type:               Bug
 Package:            DOM XML related
 Operating System:   Fedora 20 x86/64
 PHP Version:        5.5.9
 Block user comment: N
 Private report:     N

 New Comment:

This may be more of a documentation issue than a code issue. After encountering the same problem
recently, I found that the first element becomes the root element of the document. To offset this I
wrapped the html fragment in a root element, and I was able to work with it that way.

This is most likely due to our lack of understanding that the DOM Level 2 requires a document to
have a single documentElement, with children under it. I had to look that up to understand what I
was doing wrong.


Previous Comments:
------------------------------------------------------------------------
[2015-04-15 14:46:01] cmb@php.net

Well, of course the behavior is reproducible -- only the expected
and actual behavior sections in the report are mixed up.

------------------------------------------------------------------------
[2015-04-15 14:41:47] cmb@php.net

I am not able to reproduce this behavior, see
<http://3v4l.org/SFlNo>. Can you confirm?

------------------------------------------------------------------------
[2014-02-14 01:23:21] chanson at mesd dot k12 dot or dot us

Description:
------------
Using the LIBXML_HTML_NOIMPLIED predefined constant in the DomDocument class has unexpected results.

The nodeValue of any first DOMNodeList item always contains all the values of every node list item
in the collection only when the optional LIBXML_HTML_NOIMPLIED predefined constant is passed to the
loadHTML() method.

I am currently running:
- PHP Version 5.5.8
- libxml Version 2.9.1

Test script:
---------------
$html = '<h1>Foo</h1><h2>Bar</h2><p>lorem ipsum</p>';
$dom = new \DomDocument();
$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED);
$nodes = $dom->getElementsByTagName('*');
echo $nodes->item(0)->tagName . ' -> ' . $nodes->item(0)->nodeValue .
'<br/>';
foreach ($nodes as $node) {
    echo $node->tagName . ' -> ' . $node->nodeValue . '<br/>';
}

Expected result:
----------------
h1 -> FooBarlorem ipsum
h1 -> FooBarlorem ipsum
h2 -> Bar
p -> lorem ipsum

Actual result:
--------------
h1 -> Foo
h1 -> Foo
h2 -> Bar
p -> lorem ipsum


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=66712&edit=1


Thread (5 messages)

« previous php.bugs (#197131) next »