BTW,
php的 simplexml_load_string() 无法处理诸如
<im:name>The Fault in Our Stars (Unabridged)</im:name>
的xml文件,在其中的属性解析后会丢失
// 简单的xml解析示例(从xml字符串-->json数组)// $strXml为输入,$json 为输出function normalizeSimpleXML($obj, &$result) { $data = $obj; if (is_object($data)) { $data = get_object_vars($data); } if (is_array($data)) { foreach ($data as $key => $value) { $res = null; normalizeSimpleXML($value, $res); if (($key == '@attributes') && ($key)) { $result = $res; } else { $result[$key] = $res; } } } else { $result = $data; }}$strXml = ""; // xml的字符串形式$xml = simplexml_load_string($strXml);$json = normalizeSimpleXML($xml, $result);