Or you could use the XML class from [this repository][1], along with Xpath selectors, and the code would be something like: <?php $f = file_get_contents("timber.xml"); $xml = new Xms\Core\Xml($f); $order_number_val = $xml("//order-number")->text(); $xml("//shipping-address")->children("*[last()]")->to($shipping_address); ... [1]: https://github.com/mekanixms/xms