XML - Listing Children Nodes
Posted: Tue Dec 01, 2009 4:54 am
Hi,
I need something list all the nodes of an XML file in a similar way to how the print_r() function lists out an array.
So it will list out all the fields in the correct order but so that I can actually do something with them.
I'm trying to create a select box with all the fields in so that I can map the XML file into my database.
At the moment I am doing this:
Really need something that can test to see if there are any children nodes under the current node selected and keep going till it stops then move on the the next parent node.
Or something that can count all nodes within the feed and just list them one by one.
I'm sure there must be a way to do this, I just can't work out the logic.
I need something list all the nodes of an XML file in a similar way to how the print_r() function lists out an array.
So it will list out all the fields in the correct order but so that I can actually do something with them.
Code: Select all
Array
(
[a] => apple
[b] => banana
[c] => Array
(
[0] => x
[1] => y
[2] => z
)
[d] => Array
(
[0] => x
[1] => y
[2] => Array
(
[0] => Keeps going deeper...
[1] => etc...
)
)
)At the moment I am doing this:
Code: Select all
foreach($xml->children() as $child1){
foreach($child1->children() as $child2){
foreach($child2->children() as $child3){
// Obviously this could keep going for ages...
}
}
}Or something that can count all nodes within the feed and just list them one by one.
I'm sure there must be a way to do this, I just can't work out the logic.