symphonycms/symphony-2 — pull request #970 by nils-werner (2011-12-13 10:10:19+00:00)
Title: Methods to extract single XMLElement children

A member of the community recently asked for a way to manipulate/extract data from a DataSource's XML using PHP. [The result](http://symphony-cms.com/discuss/thread/81494/2/#position-23) was a bit messy because XMLElement doesn't provide a "chainable" way of accessing children by always returning an `array()`.

This PR implements two new methods that enable the developer to directly access only one single element from the returned XML. The returned value is either `NULL` or an instance of `XMLElement`.

The code by the aforementioned member

foreach($result->getChildrenByName('entry') as $entry){
foreach($entry->getChildrenByName('redirect-to') as $parent) {
foreach($parent->getChildrenByName('item') as $item){
echo $item->getAttribute('handle');
}
}
}

would become

$result->getChildByName('entry', 1)->getChildByName('redirect-to', 1)->getChildByName('item', 1)->getAttribute('handle');

Next step: Full XPath support. ;-)