php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38768 addChild to an empty node doesn't add a child
Submitted: 2006-09-10 11:48 UTC Modified: 2006-09-11 18:57 UTC
From: vondi at vondi dot no-ip dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.1.6 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vondi at vondi dot no-ip dot com
New email:
PHP Version: OS:

 

 [2006-09-10 11:48 UTC] vondi at vondi dot no-ip dot com
Description:
------------
Created a SimpleXMLObject with simplexml_load_string, then attempted to add a child to the empty node.

However the the child node isn't created.

Reproduce code:
---------------
<?
 $str="<Connector></Connector>";
 $xml=simplexml_load_string($str,'SimpleXMLElement');
 $xml->Connector->addChild('test');
 echo $xml->asXML();
?>

Expected result:
----------------
<?xml version="1.0"?>
<Connector>
 <test></test>
</Connector>


-- or --
<?xml version="1.0"?>
<Connector>
 <test />
</Connector>

Actual result:
--------------
<?xml version="1.0"?>
<Connector/>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-10 17:37 UTC] iliaa@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 are actually trying to create 2 new children, which won't 
work. In your sample HTML the Connector node is the root node, 
so to add children to it, you simply need to do
$xml->addChild('test');
or
$xml->test = 'nodeValue';
 [2006-09-11 18:57 UTC] vondi at vondi dot no-ip dot com
Ok. Thank you very much for your reply and sorry for taking your time due to my limited programming skill and logic flaws.

Keep up the very good work!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC