A
A
Andryushkov Konstantin2014-10-28 23:32:12
PHP
Andryushkov Konstantin, 2014-10-28 23:32:12

How to create a tree of loadable nodes from a random XML file?

Good time of the day.
I'm having difficulty creating a dropdown tree from a random XML file by loading nodes via ajax by clicking on them.
The whole problem is that the file was parsed using jQuery or PHP, I don’t know the exact structure, the name of the tags and the depth of nesting, so it’s impossible to sort through foreach, getElementsByTagName or through attributes. More precisely, if I know the entire structure for the current file through Simplexml,

$xml = simplexml_load_file("sample.xml");
$json = json_encode($xml);
$array = json_decode($json,TRUE);

but to write generic code for any xml i don't have enough knowledge.
In the articles I read, a tree of nodes is built based on the known structure and nesting.
If anyone has come across this issue, please let me know, I would really appreciate it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Surin, 2014-10-29
@robston

I'm not counting on a TOP1 answer, but I think it's worth seriously considering using XPath . In theory, you can easily identify the clicked node, pass it to the XPath server, and that in turn, using XPath, return exactly what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question