title: How to traverse recursively an HTML tree with Jsoup?
body: <p>I have a html file and I want to traverse the file using first div tag <a href="https://i.stack.imgur.com/KczwZ.png" rel="nofollow noreferrer">the image display the html file structure</a>
  my Code is</p>
  <pre><code>public static void ExtractChild(String content) {
  
      String data = content;
      ArrayList&lt;String&gt; childList = new ArrayList&lt;String&gt;();
      try{
      Document document = Jsoup.parse(data);
      Element div = document.select(&quot;div&quot;).first();
      Elements divChildren = div.children();
      int size = divChildren.size();
      if (size &gt; 0) {
          for (int i = 0; i &lt; size; i++) {
              data = divChildren.get(i).toString();
              
              System.out.println(data);
              ExtractChild(data);
          }
      } else {
          childList.add(data);
  
      }
      }
      catch(Exception e)
      {System.out.println(e.getMessage());
          
      }
  
  }
  }
  </code></pre>
  <p>I am getting an Html file as String First I catch First div tag and get all its all children. In my image the parent has 3 child and first child has 2 child.
  i am adding the child if it does not have any sub child( else portion) the problem occurs in If portion when it founds the sub child it reset the value of i and the it is not able to backtrack.</p>