我使用了这个树数据结构。 https://github.com/nicmart/Tree
并从以下xml代码创建了一个树对象,它们都显示在下面:
<xgameapp version="1.0">
<states>
<state id="1" color="red"></state>
<state id="2" color="blue">
Hello state
</state>
</states>
<actions>
<transitions>
<transition from="1" to="2">
This is a demo Transition
</transition>
<transition from="2" to="1"></transition>
</transitions>
<Orientations>
<x1>
<y1>
<cw>
<Orientation fronAngle="120" toAngle="45"></Orientation>
<Orientation fronAngle="270" toAngle="120"></Orientation>
</cw>
<ccw>
<Orientation fronAngle="45" toAngle="120"></Orientation>
<Orientation fronAngle="120" toAngle="270"></Orientation>
</ccw>
</y1>
</x1>
</Orientations>
</actions>
</xgameapp>
Tree\Builder\NodeBuilder Object
(
[nodeStack:Tree\Builder\NodeBuilder:private] => Array
(
[0] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => xgameapp
[attributes] => Array
(
[version] => 1.0
)
)
[parent:Tree\Node\Node:private] =>
[children:Tree\Node\Node:private] => Array
(
[0] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => states
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
[0] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => state
[attributes] => Array
(
[id] => 1
[color] => red
)
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
)
)
[1] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => state
[attributes] => Array
(
[id] => 2
[color] => blue
)
[value] =>
Hello state
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
)
)
)
)
[1] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => actions
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
[0] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => transitions
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
[0] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => transition
[attributes] => Array
(
[from] => 1
[to] => 2
)
[value] =>
This is a demo Transition
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
)
)
[1] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => transition
[attributes] => Array
(
[from] => 2
[to] => 1
)
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
)
)
)
)
[1] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => Orientations
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
[0] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => x1
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
[0] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => y1
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
[0] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => cw
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
[0] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => Orientation
[attributes] => Array
(
[fronAngle] => 120
[toAngle] => 45
)
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
)
)
[1] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => Orientation
[attributes] => Array
(
[fronAngle] => 270
[toAngle] => 120
)
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
)
)
)
)
[1] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => ccw
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
[0] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => Orientation
[attributes] => Array
(
[fronAngle] => 45
[toAngle] => 120
)
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
)
)
[1] => Tree\Node\Node Object
(
[value:Tree\Node\Node:private] => Array
(
[name] => Orientation
[attributes] => Array
(
[fronAngle] => 120
[toAngle] => 270
)
)
[parent:Tree\Node\Node:private] => Tree\Node\Node Object
*RECURSION*
[children:Tree\Node\Node:private] => Array
(
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
现在我试图将此输出表示为嵌套数组或任何对人眼友好的方式。
感谢。