I'm trying to parse this XML structure but can't find a way to parse "n"-deep nested tags using recursion. The xml structure:
<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>
The nodes are matched key - dict being the key node a version number for the data inside the dict node but the xml structure has arbrittrary dict nesting as you can see in the above code. I've got this recursive function which accepts a dict node so far but I can't see the light.
<? 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;
}
?>
keynodeValue, and the nextkeysibling data as an array I need that data to insert into the db. Let's say first <key> <dict> pair,<key>1.1.1</key> <dict> <key>nag</key> <integer>1</integer> </dict>from the <key> node I got "1.1.1", from the <dict> node an array with the following data of its children nodes key_name ="nag", type_name= "integer" and type_value="1".<dict>elements that have<key>as sibling.