title: Parsing HTML content with sibling tags in Java (or) Finding content between two <open> tags
body: <p>Background: I'm writing a Java program to go through HTML files and replace all the content in tags that are not <code>&lt;script&gt;</code> or <code>&lt;style&gt;</code> with Lorem Ipsum. I originally did this with a regex just removing everything between a > and a &lt;, which actually worked quite well (blasphemous I know), but I'm trying to turn this into a tool others may find useful so I wouldn't dare threaten the sanctity of the universe any more by trying to use regex on html.</p>
  
  <p>I'm trying to use HtmlCleaner, a Java library that attracted me because it has no other dependencies. However, trying to implement it I've been unable to deal with html like this:</p>
  
  <pre><code>&lt;div&gt;
      This text is in the div &lt;span&gt;but this is also in a span.&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The problem is simple. When the TagNodeVisitor reaches the div, if I replace its contents with the right amount of lipsum, it will eliminate the span tag. But if I drill down to only TagNodes with no other children, I would miss the first bit of text. </p>
  
  <p>HtmlCleaner has a ContentNode object, but that object has no replace method. Anything I can think of to deal with this seems like it must be far too complicated. Is anyone familiar with a way to deal with this, with HtmlCleaner or some other parsing library you're more familiar with?</p>