import javax.swing.text.html.*; import javax.swing.text.*; import java.io.*; public class HTMLDocTitle { public static void main(String argv[]) { String test = "" + "This is the title of my HTML document" + "" + "This is some text in the body of my document" + ""; HTMLEditorKit kit = new HTMLEditorKit(); HTMLDocument doc = null; try { doc = new HTMLDocument(); kit.read(new StringReader(test), doc, 0); String title = (String) doc.getProperty( Document.TitleProperty ); System.out.println("The title of the document is: " + title); /* System.out.println("The structure of the document is: "); doc.dump(System.out); */ } catch (Exception e) { System.err.println("Unexpected " + e + " thrown"); } } }