1
我需要将以下XML转换/解析为关联数组。我尝试了PHP的simplexml_load_string函数,但它没有检索属性作为关键元素。如何将XML数据作为具有属性的关联数组作为关键字PHP
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<OPS_envelope>
<header>
<version>0.9</version>
</header>
<body>
<data_block>
<dt_assoc>
<item key="protocol">XCP</item>
<item key="object">DOMAIN</item>
<item key="response_text">Command Successful</item>
<item key="action">REPLY</item>
<item key="attributes">
<dt_assoc>
<item key="price">10.00</item>
</dt_assoc>
</item>
<item key="response_code">200</item>
<item key="is_success">1</item>
</dt_assoc>
</data_block>
</body>
</OPS_envelope>
我需要这样上面的XML数据,密钥=>值对。
array('protocol' => 'XCP',
'object' => 'DOMAIN',
'response_text' => 'Command Successful',
'action' => 'REPLY',
'attributes' => array(
'price' => '10.00'
),
'response_code' => '200',
'is_success' => 1
)
试试这个@json_decode(@json_encode($ object),1); – sanj 2013-02-27 11:25:14