|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33085 Adding a DTD with insertBefore doesn't update the document doctype attribute
Submitted: 2005-05-20 16:49 UTC Modified: 2005-05-20 17:20 UTC
From: verniera at free dot fr Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.0.4 OS: Windows XP
Private report: No CVE-ID: None
 [2005-05-20 16:49 UTC] verniera at free dot fr
Adding a DTD to an already loaded document properly adds the given Element and Text to the document, but doesn't seem to update the document->doctype properly.

Workaround found: Create a new document with the DTD and import the root node of the document.

Note: It's my first try at reporting a bug, so I apologize if if it is not clear.

Reproduce code:
$impl= new DomImplementation;
$dtd= $impl->createDocumentType("test", "", "loctest.dtd");
$dom->standalone = "no";

$dom->insertBefore($dtd, $dom->firstChild);
if ($dom->validate())
  echo "Valid";
  echo "NOT Valid";

Expected result:
"NOT Valid"
An error indicating that I cannot add the DTD element

Actual result:
Notice: DOMDocument::validate() [function.validate]: No DTD given in XML-Document in C:\Inetpub\wwwroot\cgi-bin\testsDom\addDtd.php on line 26


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-20 17:20 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

You cant load a DTD after the fact.

Either reload the serialized doc you just created and validate that or build the document by hand (cannot use load methods doing this) using something like:
$doc = $impl->createDocument(NULL, 'root', $dtd);
$root = $doc->documentElement;
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 02:01:23 2020 UTC