|
| Hi!
I'm rather new to php programming, so please don't bash me if this seems
trivial to you.
What I am trying to do is write a small programm which reads an xml file
via domxml and then outputs dynamic pulldown lists (for javascript),
which depend on each other. The problem isn't generating the lists, but
rather getting php to output the elements in the right order.
Just a small xml file example:
<country>West India
<region>Assam
<location>Nalbari</location>
</region>
<region> Bihar
<location>Bodh Gaya</location>
<location>Chatra</location>
</region>
</country>
followed by further countries and regions etc.
I have no problem reading tagnames and content tags, but I'm not quite
sure on how to start.
I managed the first list by simply using get_element_by tagname, but the
first isn't dynamic.
What I need is a way to iterate through the elements and output content
of the parent and of all its child nodes (in that order). I tried to do
this recursively, but I always end up getting last children first and
then the algorithm goes back up the array and gets the next node. Giving
me this output:
West India | Assam | Nalbari | Bihar Bodh | Gaya | Chatra
Actually my code behaves, just as you would expect a tree walking
algorithm to work, it's just that I want the output in this order:
first: West India | and | all | the | other | countries...
2nd: parent:West India | Assam | Bihar
3rd: parent:Assam | Nalbari
parent:Bihar | Bodh Gaya | Chatra
Any help would be great, maybe just a hint into the right direction
would do the trick.
Thank you,
Sean
|
|