title: How to iterate through various elements in jsoup?
body: <p>I have to parse a page by jsoup. The page has a class and various elements with tags like <code>p</code>,<code>h1</code>,<code>h2</code>,<code>h3</code> etc. I want to parse them one by one, and then process each one of them. The page looks like:</p>
  
  <pre><code>    &lt;div class="pf-content"&gt;
          &lt;p&gt;For centuries, Spain shone and progressed under Muslim rule. Unfortunately, the city of Seville fell prey to the barbaric onslaught of the Kingdom of Castile in the year 1248. Several innocent Spaniards were killed, many were forced to leave their homeland and seek refuge elsewhere, whereas many others were captured and taken as slaves. The rulers of Castile further destroyed remnants of Islamic life and culture, &lt;a href="https://muslimmemo.com/masjids-spain/"&gt;including masjids&lt;/a&gt;.&lt;/p&gt;
          &lt;h3&gt;Original Arabic Text&lt;/h3&gt;
          &lt;h4&gt;Original Arabic Text&lt;/h4&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>The sequence in which p,h3,h4 etc. appears does matter, because I have to parse it to android textview. </p>
  
  <p>What I can do is : </p>
  
  <pre><code>Document document = Jsoup.connect("page link here").get();
  
  Elements pTag = document.select("div.pf-content");
  </code></pre>
  
  <p>But how should I proceed from here? Please help me.</p>
  
  <p>What I tried is: </p>
  
  <pre><code>Elements elements = document.select("div.pf-content");
  
              for (Element element : elements) {
                  Log.d("FullContent", "elements are: " + element);
                  if (element.select("p").first() != null) {
                      Log.d("FullContent", "a p tag");
                      if (element.select("p").first().select("img").first() != null) {
                          Log.d("FullContent", "the tag "  + "has src");
                      }
  
  
                  } else if (element.select("h1").first() != null) {
                      Log.d("FullContent", "a h1 tag");
                  } else if (element.select("h2").first() != null) {
                      Log.d("FullContent", "a h2 tag");
                  } else if (element.select("h3").first() != null) {
                      Log.d("FullContent", "a h3 tag");
                  } else if (element.select("h4").first() != null) {
                      Log.d("FullContent", "a h4 tag");
                  } else {
                      Log.d("FullContent", "other tag");
                  }
  
              }
  </code></pre>