I’m searching for an algorithm which will convert a data structure like the following one, where each level is separated by a dot:
child1
child1.child9
child4.child10.child11
child4.child10.child12
into a valid HTML hierarchical list element like this:
<ul>
<li>child1
<ul><li>child9</li></ul></li>
<li>child4
<ul><li>child10
<ul><li>child11</li><li>child12</li></ul></li></ul></li>
</ul>
Any suggestions?
Update
Problem
from this kind of structure(below) is easy to build hierarchical list
child
child.child1
child.child2
child.child2.child3
but my structure is
child.child2.child3
child7
child10.child14.child15
child10.child14.child16
so i dont have separate row to build parent element 🙁 i must build tree from one row if there is no parent
You could turn the list into a matrix and then use grouping/recursion. Here’s an example. It doesn’t pretty print the HTML, but it should give the correct result.