public static void main(String[] args) { try { // Create a parser, using our DTD. DomHTMLParser p = new DomHTMLParser(HTML_401F.getInstance()); HTMLDocument d = p.parseDocument(new StringReader(input)); // Print the input HTML. System.out.println(input); // Print the parsed data structure. print(System.out, d, 0); } catch (IOException ex) { ex.printStackTrace(); } }
/** * Read the document, present in the given stream, and * return the corresponding {@link HTMLDocument}. * * @param input a stream to read from. * @return a document, reflecting the structure of the provided HTML * text. * * @throws IOException if the reader throws one. */ public HTMLDocument parseDocument(Reader input) throws IOException { try { document = new DomHTMLDocument(); document.setCheckWellformedness(false); document.setCheckingCharacters(false); cursor = document; parse(input); DomHTMLDocument h = document; document = null; return h; } catch (Exception ex) { ex.printStackTrace(); throw new IOException("Exception: " + ex.getMessage()); } }