PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » XML » XML_FastCreate » Bug #6485

dynamically append child

Details

Submitted2006-01-13 14:51 UTC
Fromtrivoallan at clever-age dot net
Assignedneokod
StatusClosed
PackageXML_FastCreate
PHP Version4.3.11
OSLinux
Roadmaps(Not assigned)

Comments

[2006-01-13 14:51 UTC] trivoallan at clever-age dot net

Description:
------------
Hi,

i would like to dynamically append childs to a node. Since XML_FastCreate doesn't have an appendChild method, i've come up with a solution based on call_user_func_array. Unfortunately it doesn't work (see test script).

Test script:
---------------
$xml =& new XML_FastCreate;
$entries = array( 'a', 'b', 'c' );
$list = array();

foreach ( $entries as $entry ) {

$list[] = $xml->entry( $entry );

}

$str = call_user_func_array( array(&$this, 'entries'), $list );

// $str == NULL
var_dump( $str );

Expected result:
----------------
$str =
<entries>
<entry>a</entry>
<entry>b</entry>
<entry>c</entry>
</entries>

[2006-01-13 15:00 UTC] neokod at php dot net

If you want concat entitities, just make a string concat :
$str = join('', $list);

if you want to create tag with the value of your $entry, use the xml() method like this :
$list[] = $xml->xml($entry)

Take a look on the documentations for more informations :
http://pear.php.net/package/XML_FastCreate/docs/latest/

You can also look examples here :
http://lya.fr/pear/XML_FastCreate/tests/

And if you can read french, I have write a tutorial here :
http://wiki.lya.fr/doku.php?id=pear_xml_fastcreate

I close this ticket, it's not a bug.
For more help, use the PEAR mailing-list please.