title: get body content of html file in java
body: <p>i'm trying to get body content of html page.</p>
  
  <p>suppose this html file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
    &lt;link href="../Styles/style.css" rel="STYLESHEET" type="text/css" /&gt;
  
    &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;p&gt; text 1 &lt;/p&gt;
  &lt;p&gt; text 2 &lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>what i want is : </p>
  
  <pre><code>&lt;p&gt; text 1 &lt;/p&gt; 
  &lt;p&gt; text 2 &lt;/p&gt;
  </code></pre>
  
  <p>so, i thought that using <code>SAXParser</code> would do that (if you know simpler way please tell me)</p>
  
  <p>this is my code, but always i get <strong>null</strong> as body content:</p>
  
  <pre><code>private final String HTML_NAME_SPACE = "http://www.w3.org/1999/xhtml";
  private final String HTML_TAG = "html";
  private final String BODY_TAG = "body";
  public static void parseHTML(InputStream in, ContentHandler handler) throws IOException, SAXException, ParserConfigurationException
  {
      if(in != null)
      {
          try
          {
              SAXParserFactory parseFactory = SAXParserFactory.newInstance();
              XMLReader reader = parseFactory.newSAXParser().getXMLReader();
              reader.setContentHandler(handler);
              InputSource source = new InputSource(in);
              source.setEncoding("UTF-8");
              reader.parse(source);
          }
          finally
          {
              in.close();
          }
      }
  }
  
  public ContentHandler constrauctHTMLContentHandler()
  {
      RootElement root = new RootElement(HTML_NAME_SPACE, HTML_TAG);
      root.setStartElementListener(new StartElementListener() 
          {           
          @Override
          public void start(Attributes attributes) 
          {           
              String body = attributes.getValue(BODY_TAG);
              Log.d("html parser", "body: " + body);
          }
      });
  return root.getContentHandler();
  }
  </code></pre>
  
  <p>then</p>
  
  <pre><code>parseHTML(inputStream, constrauctHTMLContentHandler()); // inputStream is html file as stream
  </code></pre>
  
  <p>what is wrong with this code?</p>