I am using PHP 4 and XML in my project
I want to get a tree structure in my application similar to Explorer windows in Windows.
How can i Implement it???
Tree Structure using PHP and XML
Please be more specific. Now that you mention XML, do you want to display some XML data as a tree, or as your earlier post hinted, a directory tree from the computer? There is a rather large difference between the two.
Hello Dan,
XML data can be represented as a tree.
I would like to know whether we could represent a tree structure as the directory tree in the computer using PHP.
regards
Aby
Right. I was just taking into account your previous post, and I was unsure if you were represending physical directorys as a tree or XML.
Its not a question that can be easily answered here in this forum, but basically here is how I would accopmplish it.
First, familiarize yourself with xml_parse_into_struct (this is the method I prefer, I would recommend other methods for LARGE XML files though).
Then, parse the data into an array using this function. Each element is represented as an array, with various attributes (inlcuding the CDATA sections, all the attributes, and the level that the tag is on). Then, you would display EVERY element that is on level 1. Then, link them to their level-2 subcomponents. When the user clicks the link, you then display the 2nd level.
You can aslo check out a function I wrote a while back that might help you out. It turns the data from xml_parse_into_struct (a 1 dimensional array) into a real tree structure.
http://www.phpbuilder.com/snippet/detail.php?type=snippet&id=410
As I said, its not something that can be simply answered, short of us on the forum from writing the whole program for you. Hopefully this will help you out though.