glaszig/snippets — pull request #2 by pschultz (2012-04-23 21:41:25+00:00)
Title: Support for siblings with same name

Adding support for the following:

$xml = new XmlBuilder;
$xml->families->doe[0] = 'john';
$xml->families->doe[1] = 'jane';
echo $xml;

gives:

john
jane

This works as well:

$xml->families->doe[0] = 'john';
$xml->families->doe[1] = 'jane';
$xml->families->doe[0]['gender'] = 'male';
$xml->families->doe[1]['gender'] = 'female';

Note that the nodes are discontinuous, because that is how numerically indexed arrays work in PHP. So this is the same as the first example:

$xml = new XmlBuilder;
$xml->families->doe[0] = 'john';
$xml->families->doe[5] = 'jane';
echo $xml;

`DOMNodeList::item($index)` however is not. So

$xml = new XmlBuilder;
$xml->families->doe[0] = 'john';
$xml->families->doe[5] = 'jane';
$xml->build();
unset($xml->families->doe[5]);
echo $xml;

might not work as expected (`jane` is still in the resulting xml).