title: Convert Iterator to a for loop with index in order to skip objects
body: <p>I am using <a href="http://jericho.htmlparser.net/docs/javadoc/index.html" rel="nofollow">Jericho HTML Parser</a> to parse some malformed html. In particular I am trying to get all text nodes, process the text and then replace it.</p>
  
  <p>I want to skip specific elements from processing. For example I want to skip all  elements, and any element that has attribute class="noProcess". So, if a div has class="noProcess" then I want to skip this div and all children from processing. However, I do want these skipped elements to return back to the output after processing.</p>
  
  <p>Jericho provides an Iterator for all nodes but I am not sure how to skip complete elements from the Iterator. Here is my code:</p>
  
  <pre><code>private String doProcessHtml(String html) {
          Source source = new Source(html);
          OutputDocument outputDocument = new OutputDocument(source);
  
          for (Segment segment : source) {
              if (segment instanceof Tag) {
                  Tag tag = (Tag) segment;
                  System.out.println("FOUND TAG: " + tag.getName());
  
                  // DO SOMETHING HERE TO SKIP ENTIRE ELEMENT IF IS &lt;A&gt; OR CLASS="noProcess"
  
              } else if (segment instanceof CharacterReference) {
                  CharacterReference characterReference = (CharacterReference) segment;
                  System.out.println("FOUND CHARACTERREFERENCE: " + characterReference.getCharacterReferenceString());
              } else {
                  System.out.println("FOUND PLAIN TEXT: " + segment.toString());
                  outputDocument.replace(segment, doProcessText(segment.toString()));
              }
          }
  
         return outputDocument.toString();
      }
  </code></pre>
  
  <p>It doesn't look like using the ignoreWhenParsing() method works for me as the parser just treats the "ignored" element as text.</p>
  
  <p>I was thinking that if I could convert the Iterator loop to a for (int i = 0;...) loop I could probably be able to skip the element and all its children by modifying i to point to the EndTag and then continue the loop.... but not sure.</p>