I am getting XML data from an api that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<PP>
<row merchant_id="" customer_code="" billing_name="" account_status="Active" created_date="2013-07-31 13:22:32.687" last_modified_date="2013-07-31 13:23:41.827" last_trans_date="2013-07-31 13:35:59.257" billing_address1="rd." billing_address2="" billing_city="Lower" billing_province_id="" billing_country_id="CA" billing_postal="" billing_email_address="" billing_phone="" velocity_group="" profile_group="" account_ref="12345" card_expiry="0713" cc_notification="" ref1="" ref2="" ref3="" ref4="" ref5="" />
</PP>
I am trying to either access the data in php or turn it into an easily accessible array. I have tried something like this:
$xml = simplexml_load_string($resp);
$fields = array();
foreach ($xml->field as $f) {
$f = (array) $f->attributes();
$fields[] = $f['@attributes'];
}
But cannot access the data from that.
When I print that data it shows as this:
SimpleXMLElement Object ( [row] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [merchant_id] => [customer_code] => [billing_name] => John Doe [account_status] => Active [created_date] => 2013-08-01 08:26:31.710 [last_modified_date] => 2013-08-01 08:26:52.170 [last_trans_date] => [billing_address1] => [billing_address2] => [billing_city] => [billing_province_id] => [billing_country_id] => CA [billing_postal] => [billing_email_address] => .ca [billing_phone] => [velocity_group] => [profile_group] => [account_ref] => [card_expiry] => 0813 [cc_notification] => [ref1] => [ref2] => [ref3] => [ref4] => [ref5] => ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [merchant_id] => [customer_code] => 12345 [billing_name] => [account_status] => Active [created_date] => 2013-07-31 13:22:32.687 [last_modified_date] => 2013-07-31 13:23:41.827 [last_trans_date] => 2013-07-31 13:35:59.257 [billing_address1] => rd. [billing_address2] => [billing_city] => Lowe [billing_province_id] => [billing_country_id] => CA [billing_postal] => [billing_email_address] => [billing_phone] => [velocity_group] => [profile_group] => [account_ref] => 12345 [card_expiry] => 0713 [cc_notification] => [ref1] => [ref2] => [ref3] => [ref4] => [ref5] => ) ) ) )
Can anyone help me out on either just accessing the data or help me put this into an array.
Thanks