html5-php
html5-php copied to clipboard
DOMElement::setIdAttribute(): ID loading already defined
Hello,
Sometimes i get strange error:
PHP Warning: DOMElement::setIdAttribute(): ID loading already defined in /home/xxx/domains/xxx/public_html/xxx/core/framework/Masterminds/HTML5/Parser/DOMTreeBuilder.php on line 392
PHP Stack trace:
PHP 1. {main}() /home/xxx/domains/xxx/public_html/index.php:0
PHP 2. Core\xxx->loadPage() /home/xxx/domains/xxx/public_html/index.php:147
PHP 3. Modules\xxx\Main->load() /home/xxx/domains/xxx/public_html/xxx/core/xxx.php:619
PHP 4. Modules\xxx\Main->_startEngine() /home/xxx/domains/xxx/public_html/xxx/modules/xxx/main.php:301
PHP 5. Modules\xxx\Main->_runCrawler() /home/xxx/domains/xxx/public_html/xxx/modules/xxx/main.php:121
PHP 6. Core\Classes\Search\Crawler->visitPage() /home/xxx/domains/xxx/public_html/xxx/modules/xxx/main.php:154
PHP 7. Masterminds\HTML5->loadHTML() /home/xxx/domains/xxx/public_html/xxx/core/classes/search/crawler.php:28
PHP 8. Masterminds\HTML5->parse() /home/xxx/domains/xxx/public_html/xxx/core/framework/Masterminds/HTML5.php:94
PHP 9. Masterminds\HTML5\Parser\Tokenizer->parse() /home/xxx/domains/xxx/public_html/xxx/core/framework/Masterminds/HTML5.php:165
PHP 10. Masterminds\HTML5\Parser\Tokenizer->consumeData() /home/xxx/domains/xxx/public_html/xxx/core/framework/Masterminds/HTML5/Parser/Tokenizer.php:83
PHP 11. Masterminds\HTML5\Parser\Tokenizer->tagOpen() /home/xxx/domains/xxx/public_html/xxx/core/framework/Masterminds/HTML5/Parser/Tokenizer.php:126
PHP 12. Masterminds\HTML5\Parser\Tokenizer->tagName() /home/xxx/domains/xxx/public_html/xxx/core/framework/Masterminds/HTML5/Parser/Tokenizer.php:269
PHP 13. Masterminds\HTML5\Parser\DOMTreeBuilder->startTag() /home/xxx/domains/xxx/public_html/xxx/core/framework/Masterminds/HTML5/Parser/Tokenizer.php:371
PHP 14. DOMElement->setIdAttribute() /home/xxx/domains/xxx/public_html/xxx/core/framework/Masterminds/HTML5/Parser/DOMTreeBuilder.php:392
PHP Warning: DOMElement::setIdAttribute(): ID placeholder already defined in /home/xxx/domains/xxx/public_html/xxx/core/framework/Masterminds/HTML5/Parser/DOMTreeBuilder.php on line 392
I don't know what the input is, but i hope you can help me?
Do you have some HTML that causes this error? I'd like to try and reproduce it.
I currently have no html code at my disposal, but what php version are you using? I am using PHP 5.6.2.
It appears travis ci is testing against 5.6.0 (https://travis-ci.org/Masterminds/html5-php/jobs/36731725) and everything is passing there. That's part of the reason I was wondering about an html example with the issue. Travis tests against php 5.3 - 5.6 plus hhvm.
Tomorrow i have a html example for you. Thank for looking for the problem.
Tonight I have a html code for you, but on the internet I found this problem: http://stackoverflow.com/questions/3614586/dom-error-id-someanchor-already-defined-in-entity-line
Maybe is that the problem?
Sorry, i have no html code for you. The HTML code is dynamic and it is not possible to track the code because i got a php warning before the code going to the log system...
PHP 5.6.3 has a new version of libxml2: 2.9.2. This problem was also reported against Drupal (7 and 8), where this library is not even being used (yet).
See https://www.drupal.org/node/2386903.
has someone a piece of html to test this issue?
Here it is (on ubuntu 15.04, php 5.6) http://goo.gl/QmDpZE
The id mb1 is actually repeated many times but the parser should be able to handle such situation (?) which turns out to be common
Fails with Warning: DOMElement::setIdAttribute(): ID mb1 already defined
Stack trace
vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php:424
Symfony\Component\Debug\ErrorHandler->handleError() at n/a:n/a
DOMElement->setIdAttribute() at vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php:424
Masterminds\HTML5\Parser\DOMTreeBuilder->startTag() at vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php:380
Masterminds\HTML5\Parser\Tokenizer->tagName() at vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php:278
Masterminds\HTML5\Parser\Tokenizer->tagOpen() at vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php:126
Masterminds\HTML5\Parser\Tokenizer->consumeData() at vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php:83
Masterminds\HTML5\Parser\Tokenizer->parse() at vendor/masterminds/html5/src/HTML5.php:173
Masterminds\HTML5->parse() at vendor/masterminds/html5/src/HTML5.php:98
Masterminds\HTML5->loadHTML() at vendor/querypath/querypath/src/QueryPath.php:241
Thank you Best, Luca
While I'm not sure how the situation should be handled, it is most definitely an error to try to set the same ID on multiple elements. And part of the reason for this is that there should be a lookup table of ID to element.
Any ideas on what the right way to handle this is? First to set the ID wins? Last to set the ID wins?
I guess the last win as it is the last known unique id found, but seems more a matter of taste :)
I don't know about the internals of the library but the table lookup seems a nice way to handle multiple ids. It could not differ too much from how a class property is handled only in the case where there are more than one id
Best
I've had an occurrence of this reported by a user of wp-Typography in https://github.com/mundschenk-at/wp-typography/issues/12. While clearly an bug in another plugin (producing invalid HTML), it would be great if the parser was more "real world friendly". Maybe an option to be more lenient?
@goetas Do you still need additional feedback for this or is @muka's example sufficient?
Actually nobody managed yet to provide a failing test case for this issue.
Having a test that demonstrates the problem, will help the resolution of it
Ah think @muka had linked a test case, but it's gone by now. I'll try to come up with a small example.