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
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.
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")?
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.
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;
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.
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.
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.