title: How can I determine if a HTML document is well formed or not in JAVA?
body: <p>Heyy guys, I need to determine if a given HTML Document is well formed or not.<br>
  I just need a simple implementation using only Java core API classes i.e. no third party stuff like JTIDY or something. Thanks.</p>
  
  <p>Actually, what is exactly needed is an algorithm that scans a list of TAGS. If it finds an open tag, and the next tag isn't its corresponding close tag, then it should be another open tag which in turn should have its close tag as the next tag, and if not it should be another open tag and then its corresponding close tag next, and the close tags of the previous open tags in reverse order coming next on the list. I've already written methods to convert a tag to a close tag. If the list conforms to this order then it returns true or else false.  </p>
  
  <p>Here is the skeleton code of what I've started working on already. Its not too neat, but it should give you guys a basic idea of what I'm trying to do.  </p>
  
  <pre><code>public boolean validateHtml(){
  
      ArrayList&lt;String&gt; tags = fetchTags();
      //fetchTags returns this [&lt;html&gt;, &lt;head&gt;, &lt;title&gt;, &lt;/title&gt;, &lt;/head&gt;, &lt;body&gt;, &lt;h1&gt;, &lt;/h1&gt;, &lt;/body&gt;, &lt;/html&gt;]
  
      //I create another ArrayList to store tags that I haven't found its corresponding close tag yet
      ArrayList&lt;String&gt; unclosedTags = new ArrayList&lt;String&gt;();
  
      String temp;
  
      for (int i = 0; i &lt; tags.size(); i++) {
  
          temp = tags.get(i);
  
          if(!tags.get(i+1).equals(TagOperations.convertToCloseTag(tags.get(i)))){
              unclosedTags.add(tags.get(i));
              if(){
  
              }
  
          }else{
              return true;//well formed html
          }
      }
  
      return true;
  }
  </code></pre>