Avatar of PaulyWolly
PaulyWolly
 asked on

I need to create a treeview folder structure based off xml output, using JQuery or APEX

I am trying to put together a page in Oracle APEX, but for now I have a PHP page, xml_gen.php which generates XML as output from a read from a query to an Oracle database. I have attached the page I am using to generate the xml output (xml_gen.txt is really xml_gen.php), and a sample of the output as xml.

What I need to do is create a treeview folder structure based off this xml output, using JQuery or APEX. I have looked for some treeview .js libraries and many are great for rendering the tree if i save the output as an XML file and then feed the XML file to the tree routine.

What I really need is to be able to generate the tree from the xml_gen.php output directly.

I had thought about sending the output to a session variable and then reading the session into the tree routine but I am not sure how to write that.

Does anyone have an idea as to how i would go about creating a treeview structure from a read of the xml_gen.php page using JQuery or APEX framework in Oracle?
xml-gen.txt
xml-gen.xml
Oracle DatabasejQueryJavaScript

Avatar of undefined
Last Comment
PaulyWolly

8/22/2022 - Mon
PaulyWolly

ASKER
increasing points
alien109

If I'm understanding the problem correctly, you want the php file to generate the html for the tree?
PaulyWolly

ASKER
if that is what is needed... then yes. The xml-gen.php file generates the XML, then possibly another php page can read the xml output from the first page and generate the tree structure. As I said earlier, I can generate a treeview structure no problem if I feed an actual XML file with a .XML extension to the page wanting to create the treeview, but I do not have that here. The situation I have is that a PHP file reads the database and creates an output of XML. I need to be able to read that output and then OUTPUT IT as a treeview folder structure from the xml-gen.php page.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
PaulyWolly

ASKER
if you look at the xml-gen.txt (xml-gen.php) page I attached, you will see that it creates output as XML - it does not write an XML file, but creates output AS xml.
PaulyWolly

ASKER
Most of the treeview JS frameworks that are found on the web will create a treeview from XML. I have a php file that creates XML as output, but does not create an XML file. I need a php page or JS file that can read the output from the xml-gen page and create a dynamic treeview on the fly from the read.
David S.

Do you mean that you're not using the header() function to set the content-type to an XML content-type (e.g. "application/xml")?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
PaulyWolly

ASKER
if you look at the attached file above, you will see.
David S.

Have you tried simply using jQuery to do a normal AJAX request to read the output of that PHP script?
PaulyWolly

ASKER
can you give me an example? if you need me to offer more points i can.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
David S.

This looks like a good tutorial on doing that (it does cover some steps that you've already done though): http://articles.sitepoint.com/article/ajax-jquery 

P.S. An increase in points would not make a difference to me.
PaulyWolly

ASKER
this article is good but it looks like i am going to have to fabricate something on my own using tutorials like this and js libraries like 'jstree' to come up with a way to read the output from the xml_gen.php to create a treeview on a new page.i really was hoping for a working example.

PaulyWolly

ASKER
i guess i can give you credit Kravimir for pointing this page out to me... and you are right, it does cover steps i have already done.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
alien109

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
PaulyWolly

ASKER
hi alien109. thanks for this.
if you look at the file i attached - xml_gen.txt you can see that it does a connection to an Oracle db, does a query to the 'trees' table and pulls out column data based on a 'build_id' passed to the page.

the output from the query is then processed as xml using this:

===========

$doc = new DOMDocument('1.0', 'UTF-8');
            $root = $doc->createElement('root');        // first one
            $root = $doc->appendChild($root);
            $node = $root;
            $previous_level = 0;

            while ($row = oci_fetch_array($stid)) {
                $level      = $row['LEVEL'];
                $name       = $row['NAME'];
                $filepath   = $row['PATH'];

                while ($previous_level >= $level) {
                    $node = $node->parentNode;
                    $previous_level--;
                }

                $item = $doc->createElement('item');
                $node = $node->appendChild($item);
                $content = $doc->createElement('content');
                $node = $item->appendChild($content);
                $name = $node->appendChild($doc->createElement('name', $name));
                $filepath = $node->appendChild($doc->createElement('file_path', $filepath));
                $previous_level = $level+1;
            }
            oci_free_statement($stid);
        }
        catch (Exception $e)
        {
            echo "Caught exception: ",  $e->getMessage(), "\n";
        }
        oci_close($conn);

        header('Content-type: application/xml');      
            echo $doc->saveXML();

PaulyWolly

ASKER
i suppose this page could be re-written to output a treeview instead of xml here:

header('Content-type: application/xml');      
            echo $doc->saveXML();
alien109

I would say that unless the XML is needed elsewhere in the application/site that the XML is an unnecessary step since the goal is to render HTML. If you still need to generate the data in a format that consumable by other scripts, you might consider JSON as an alternative since it is already native to JavaScript and much less verbose.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
alien109

Yes - I would change your PHP script that generates the XML to simply generate HTML instead, and output that to the page.
PaulyWolly

ASKER
how would I convert the page to output JSON?
PaulyWolly

ASKER
I see that jstree is a pretty good tree solution. but in each case it wants to read an actual file (.xml. .js, html, etc.) , not output and translate it.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
PaulyWolly

ASKER
I guess the problem here is I do not have a real clue as to how to create the tree unless I have an actual file to read, like what JSTREE wants.
alien109

I'm confused again.

Lets say you want a tree view on index.php. In index.php, you would generate the HTML for the tree, and then call the javascript. The javascript runs on the client side. It formats and binds all of the events for the tree. The tree doesn't "read" any file. It simply looks into the HTML structure and finds the HTML that you have outputted and uses that for the tree.

Basically -

You read data from your database. You translate the data structure into the tree view HTML and output that to the page. Then using javascript, you call the plugin and provide the appropriate DOM selector and that's it.

I don't get what you mean, I guess.
PaulyWolly

ASKER
alien109 - please give me a simple example of what you are stating. then I can see what you are saying and have a better idea. Sometimes actual code says more than words.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
PaulyWolly

ASKER
I had to do more research to find an example but when I did it was close to what was provided, so I am giving the points.