You can do this rather easily using SimpleXMLElement::xpath
and array_map
.
$values = array_map(function($node) {
return (string) $node['TEXT'];
}, $xml->xpath('//node[not(node)]'));
You can see that first we get an array of node that do not have children, then we transform each of those nodes into a string containing the node's TEXT
attribute.