I have HTML lists with the exact same structure that I need to parse using JSoup (my language is Java). Here's an example:
<div class="ulist">
<ul>
<li><p>Healthy Food</p></li>
<div class="ulist">
<ul>
<li><p>Vegetables</p></li>
<div class="ulist">
<ul>
<li> <p>Carrots</p> </li>
<li> <p>Lettuce</p> </li>
<li> <p>Cucumbers</p> </li>
</ul>
</div> </li>
<li> <p>Fruits</p>
<div class="ulist">
<ul>
<li> <p>Apples</p> </li>
<li> <p>Bananas</p> </li>
<li> <p>Canned Fruits</p></li>
<div class="ulist">
<ul>
<li> <p>Peaches</p> </li>
<li> <p>Pears</p> </li>
</ul>
</div>
</ul>
</div>
</li>
</ul>
</div>
</ul>
</div>
Since this data is basically just a Tree data structure, I want to be able to parse it and create a Tree from the data. I'm having difficulty doing this with JSoup, as it appears you can't really traverse the DOM as expected.
For example, code like the following:
Elements elList = doc.select("ul");
for (Element el: elList){
Elements subList = el.select("ul");
for (Element subEl : subList){
//do whatever you need to do
}
}
Produces the following results, where it appears it's not "walking" or "traversing" down, but rather keeps selecting the same thing from the doc:

What is some code that will traverse this list and put it in a tree structure?
Element list = doc.select("ul").first();, if I then call the same code again on the resultsElement subList = list.select("ul").first();, I get the same results as the first call. I guess I'm expecting the library to "consume" only the selected section. Not sure if this makes sense.