Here's the basic "xml_node" class:
Code: Select all
class xml_node {
public $node_name;
public $children;
}And here's the basic construction of a very simple XML doc.
Code: Select all
$xml = new xml_node('brands');
$children[] = new xml_node('brand', 'Sipura', array("id" => 1));
$children[] = new xml_node('brand', 'LinkSys', array("id" => 2));
$children[] = new xml_node('brand', 'Apple', array("id" => 3));
$xml -> set_children($children);The print_r output of the above looks like:
Code: Select all
xml_node Object
(
[node_name:private] => brands
[attributes:private] =>
[node_value:private] =>
[children:private] => Array
(
[0] => xml_node Object
(
[node_name:private] => brand
[attributes:private] => Array
(
[id] => 1
)
[node_value:private] => Sipura
[children:private] =>
)
[1] => xml_node Object
(
[node_name:private] => brand
[attributes:private] => Array
(
[id] => 2
)
[node_value:private] => LinkSys
[children:private] =>
)
[2] => xml_node Object
(
[node_name:private] => brand
[attributes:private] => Array
(
[id] => 3
)
[node_value:private] => Apple
[children:private] =>
)
)
)What's the best way to loop through this, so that, when it starts, it creates the first (root) node, checks that node for children, if children exist, go to the first child, create that node, then check that node for children and so on. Once it finds no more children, go back to the last "branch" where children were found and move to the next child. It seems a simple idea to me, but I just can't wrap my head around it. I've tried a bunch of things, and saw the only solution as using a recursive function, but could only -sort of- get it working
I'm fairly new to OOP in general, so please excuse any stupid mistakes of mine in the above code.
Thanks!