find nesting depth

IsoW

New Member
So, take this html for example:\[code\]<ul> <li> <a href="http://stackoverflow.com/questions/3555981/#">Test</a> <ul> <li><a href="http://stackoverflow.com/questions/3555981/#">Test</a></li> <li><a href="http://stackoverflow.com/questions/3555981/#">Test</a></li> <li><a href="http://stackoverflow.com/questions/3555981/#">Test</a></li> <li><a href="http://stackoverflow.com/questions/3555981/#">Test</a></li> </ul> </li> <li> <a href="http://stackoverflow.com/questions/3555981/#">Test</a> <ul> <li><a href="http://stackoverflow.com/questions/3555981/#">Test</a></li> <li> <a href="http://stackoverflow.com/questions/3555981/#">Test</a> <ul> <li><a href="http://stackoverflow.com/questions/3555981/#">Test</a></li> <li><a href="http://stackoverflow.com/questions/3555981/#">Test</a></li> <li><a href="http://stackoverflow.com/questions/3555981/#">Test</a></li> <li><a href="http://stackoverflow.com/questions/3555981/#">Test</a></li> </ul> </li> </ul> </li></ul>\[/code\]I want to find out the maximum depth of this structure, in this example it would be 3, as the structure goes 3 levels down. But the structure can have an arbitrary depth.Either a javascript/jquery solution or a PHP based solution using the DOM extension would be fine. I really cant think of any nice way of doing this. Maybe there is an xpath expression that does exactly what I want?EDIT: To clarify: Depth in this case is the maximum nesting of \[code\]ul\[/code\] elements, in this case 3.
 
Back
Top