php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: verniera at free dot fr
New email:
PHP Version: OS:

 

 [2005-05-20 16:49 UTC] verniera at free dot fr
Description:
------------
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=DOMDocument::load('C:\\Inetpub\\wwwroot\\cgi-bin\\testsDom\\test.xml');
$dom->standalone = "no";

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


Expected result:
----------------
"Valid"
OR
"NOT Valid"
OR
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

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;
$root->appendChild(xxx)....
$doc->validate();
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 02:01:23 2020 UTC