php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48502 Error in constructor for DOMElement
Submitted: 2009-06-09 05:35 UTC Modified: 2009-09-25 15:35 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: trex6 at mail dot ru Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.9 OS: GNU/Linux
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: trex6 at mail dot ru
New email:
PHP Version: OS:

 

 [2009-06-09 05:35 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-09 05:58 UTC] 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:58 UTC] chregu@php.net
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)
 [2009-09-25 15:35 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

as Rasmus indicated use saveXML to get closing tag because there is none 
in HTML.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 10:01:32 2024 UTC