#48502 [Bgs->Opn]: Error in constructor for DOMElement

From: Date: Tue, 09 Jun 2009 05:58:15 +0000
Subject: #48502 [Bgs->Opn]: Error in constructor for DOMElement
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-138129@lists.php.net to get a copy of this message
ID: 48502 Updated by: chregu@php.net Reported By: trex6 at mail dot ru -Status: Bogus +Status: Open Bug Type: DOM XML related Operating System: GNU/Linux PHP Version: 5.2.9 New Comment: Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. If I make a complete script out of your snippet like *** <?php $dom = new domdocument(); $dom->loadXML("<foo/>"); $ParentElement = $dom->documentElement; $imgPic = new DOMElement("img"); $ParentElement->appendChild($imgPic); $imgPic->setAttribute("src","./1.jpg"); print $dom->saveXML(); *** I get <?xml version="1.0"?> <foo><img src="./1.jpg"/></foo> which looks perfectly fine to me. So please send a complete, reproducable script. And: You should use domdocument->createElement() and not new domelement (but doesn't seem to be the root of the problem) Previous Comments: ------------------------------------------------------------------------ [2009-06-09 05:58:08] rasmus@php.net If you use saveXML() it does. If you use saveHTML(), it doesn't because that is how it is supposed to be in HTML. If you want XHTML, use saveXML() ------------------------------------------------------------------------ [2009-06-09 05:35:39] trex6 at mail dot ru Description: ------------ I want add img element to my xml document. Reproduce code: --------------- $imgPic = new DOMElement("img"); $ParentElement->appendChild($imgPic); $imgPic->setAttribute("src","./1.jpg"); Expected result: ---------------- <img src="./1.jpg" /> Actual result: -------------- <img src="./1.jpg"> Script doesn`t generate closled '/' for tag img. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48502&edit=1

« previous php.bugs (#138129) next »