|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-04-11 19:40 UTC] jameswithers89 at googlemail dot com
Description:
------------
The product of DOMDocument::createDocument() appends children outside of the qualified name of the document element (i.e. the root element).
I am using php-5.3.2-1.fc12.i686 and php-xml-5.3.2-1.fc12.i686 installed using Yellowdog Updater, Modified Package Manager. All other DOM methods tried so far work fine.
Test script:
---------------
<?php
$implementation = new DOMImplementation();
$doctype = $implementation->createDocumentType('html');
$document = $implementation->createDocument('http://www.w3.org/1999/xhtml', 'html', $doctype);
$head = $document->createElement('head');
$document->appendChild($head);
echo $document->saveHTML();
Expected result:
----------------
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
</html>
Actual result:
--------------
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"></html><head></head>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
The following code also produces the same error: <?php $implementation = new DOMImplementation(); $doctype = $implementation->createDocumentType('html'); // Don't create a root element... $document = $implementation->createDocument(null, null, $doctype); // ...instead create a <html> element and set the xmlns attribute: $html = $document->createElement('html'); $html->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); $document->appendChild($html); $head = $document->createElement('head'); $document->appendChild($head); echo $document->saveHTML();