Validate Html example in selenium script
<p>I'm writing an automated test framework where after each action (loading a new page etc) I want to validate the html that is produced.  I am writing the framework in java and the tests may be run in an environment which is sitting behind a firewall etc.</p>

<p>I currently have the html in string format so I am looking for a way to verify that the html in the string is valid.  I was looking at jTidy but I can't find a good example of how to do this.  Does anyone have any idea?</p>

<p>Also further down the track I might look at validating the css files, so if suggestions could take that into consideration.</p>

<p>Thanks in advance,
James</p>

<p>Edit:</p>

<p>I have something working in JTidy now, hoping someone more knowlegable can verify it.  How can I print out the errors from it?</p>

<pre><code>tidy = new Tidy();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    String html = ScenarioFramework.driver.getHtml();
    try {
        Node node = tidy.parse(new ByteArrayInputStream(html.getBytes("UTF-8")), os);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    } 

    if ((tidy.getParseErrors() &gt; 0) || (tidy.getParseWarnings() &gt; 0)) { 

        System.out.println("Tidy Parser errors: " + tidy.getParseErrors());
        System.out.println("Tidy Parser warnings: " + tidy.getParseWarnings());
        return false;
    } else{
        //return with no error
        return true;
    }
</code></pre>
