我正在尝试解析这个 XML 结构,但找不到使用递归解析“n”深度嵌套标签的方法。xml结构:
<plist version="1.0">
<key>1.1.1</key>
<dict>
<key>nag</key>
<integer>1</integer>
</dict>
<key>2.2.2</key>
<dict>
<key>nag</key>
<integer>1</integer>
</dict>
<key>3.3.3</key>
<dict>
<key>show_upgrade_button</key>
<integer>0</integer>
<key>nag_startup</key>
<dict>
<key>nag_gameover</key>
<integer>3</integer>
</dict>
<key>my_stuff</key>
<string>1=cb 2=rm 3=cb+rm =leave banner ads off</string>
</dict>
<key>4.4.4</key>
<dict>
<key>nag</key>
<integer>1</integer>
</dict>
</plist>
节点匹配key
-dict
作为关键节点,节点内部数据的版本号,dict
但 xml 结构具有任意dict
嵌套,如您在上面的代码中所见。我有这个递归函数,dict
到目前为止它接受一个节点,但我看不到光。
<? php
function recursiveNodes($nodes, $arr){
$count=0;
if($nodes->hasChildNodes() === true ){
foreach($nodes->childNodes as $node){
$temp = array();
if($node->nodeName === 'key'){
$temp['key_name'] = $node->nodeValue;
if($node->nextSibling->nodeName !== 'dict'){
$sibling = $node->nextSibling;
$temp['type_name'] = $sibling ->nodeName;
$temp['value_name'] = $sibling ->nodeValue;
}
if($sibling->nodeName === 'dict'){
return recursiveNodes($sibling, $arr[$count++][]=$temp);
}
}
}
}
return $arr;
}
?>