DOMDocument
ML Expat Parser
SimpleXML
XMLReader
...
自己看看用什么方法来解析~
哪里解决不了?
比如这样吧,遍历层层解析:
header("Content-type:text/html; Charset=utf-8");
$content = "
0
成功
";
// $xml = simplexml_load_file("test.xml");
$xml = simplexml_load_string($content);
echo '第一层:' . $xml->getName() . "
";
foreach($xml->children() as $child){
echo '第二层:' . $child->getName(). "
";
foreach($child->children() as $subChild){
echo '第三层:' . $subChild->getName() . "
";
foreach($subChild->children() as $item){
echo $item->getName() . ": " . $item . "
";
}
}
}
输出:
第一层:commpara
第二层:itempara
第三层:pararow
retcode: 0
retstr: 成功
更简单粗暴的XML转数组,这样子:
$content = "
0
成功
";
$xml = simplexml_load_string($content);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
print_r($array);
输出,直接就是个数组:
Array
(
[itempara] => Array
(
[pararow] => Array
(
[retcode] => 0
[retstr] => 成功
)
)
)