title: How to change HTML tag content in Java?
body: <p>How can I change HTML content of tag in Java? For example:</p>
  
  <p>before:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div&gt;text&lt;div&gt;**text**&lt;/div&gt;text&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>after:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div&gt;text&lt;div&gt;**new text**&lt;/div&gt;text&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I tried JTidy, but it doesn't support <code>getTextContent</code>. Is there any other solution?</p>
  
  <hr>
  
  <p>Thanks, I want parse no well-formed HTML. I tried TagSoup, but when I have this code:</p>
  
  <pre><code>&lt;body&gt;
  sometext &lt;div&gt;text&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>and I want change "sometext" to "someAnotherText," and when I use <code>{bodyNode}.getTextContent()</code> it gives me: "sometext text"; when I use <code>setTextContet("someAnotherText"+{bodyNode}.getTextContent())</code>, and serialize these structure, the result is <code>&lt;body&gt;someAnotherText sometext text&lt;/body&gt;</code>, without <code>&lt;div&gt;</code> tags. This is a problem for me.</p>