View Javadoc

1   package com.quiotix.html.example;
2   
3   import java.io.FileInputStream;
4   import java.io.IOException;
5   import java.io.InputStream;
6   
7   import com.quiotix.html.parser.HtmlDocument;
8   import com.quiotix.html.parser.HtmlDumper;
9   import com.quiotix.html.parser.HtmlParser;
10  import com.quiotix.html.parser.HtmlScrubber;
11  
12  /**
13   * Example class which parses an HTML document, cleans it up a little
14   * bit, and dumps it to standard out.  Demonstrates use of the parser and 
15   * parser utilities.  
16   *
17   * Syntax: HtmlParse file
18   *
19   * Part of the Quiotix Html Parser package.  
20   * See http://www.quiotix.com/opensource/html-parser for more information
21   */
22  
23  public class HtmlParse {
24  
25    /**
26     * Runnable.
27     */
28    public static void main (String args[]) throws IOException {
29      InputStream r;
30      HtmlDocument document;
31  
32      for (int i=0; i < args.length; i++) { 
33        r = new FileInputStream(args[i]);
34      
35        try { 
36          document = new HtmlParser(r).HtmlDocument();
37          document.accept(new HtmlScrubber(HtmlScrubber.DEFAULT_OPTIONS 
38                                           | HtmlScrubber.TRIM_SPACES));
39          document.accept(new HtmlDumper(System.out));
40        }
41        catch (Exception e) {
42          e.printStackTrace();
43        }
44        finally {
45          r.close();
46        }
47      }
48      
49    }
50  }