title: How to get element by tags using JSoup? - java
body: <p><strong>How to get element by tags using JSoup (<a href="http://jsoup.org/" rel="nofollow">http://jsoup.org/</a>)?</strong></p>
  
  <p>I have the following input and require the following output but i am not getting the text inside the <code>&lt;source&gt;...&lt;\source&gt;</code> tags:</p>
  
  <p><strong>[in:]</strong></p>
  
  <pre><code>&lt;html&gt;
    &lt;something&gt;
      &lt;source&gt;foo bar bar&lt;/source&gt;
    &lt;something&gt;
    &lt;source&gt;foo foo bar&lt;/source&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>[desired out:]</strong></p>
  
  <pre><code>foo bar bar
  foo foo bar
  </code></pre>
  
  <p>I have tried this:</p>
  
  <pre><code>import java.io.*;
  import java.util.List;
  
  import org.apache.commons.io.IOUtils;
  import org.jsoup.Jsoup;
  import org.jsoup.nodes.Document;
  import org.jsoup.nodes.Element;
  
  public class HelloJsoup {
      public static void main(String[] args) throws IOException {
  
          String br = "&lt;html&gt;&lt;source&gt;foo bar bar&lt;/source&gt;&lt;/html&gt;";
          Document doc = Jsoup.parse(br);
          //System.out.println(doc);
          for (Element sentence : doc.getElementsByTag("source"))
              System.out.print(sentence);
  
      }
  }
  </code></pre>
  
  <p>but it outputs:</p>
  
  <pre><code>&lt;source&gt;&lt;/source&gt;
  </code></pre>