Tidy tidy = new Tidy(); Document doc = tidy.parse(inputStream); import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.w3c.tidy.Tidy; import java.io.FileInputStream; import java.io.InputStream; public class JTidyExample { public static void main(String[] args) throws Exception { Tidy tidy = new Tidy(); tidy.setQuiet(true); tidy.setXHTML(true); InputStream inputStream = new FileInputStream("input.html"); Document doc = tidy.parse(inputStream); NodeList titleElements = doc.getElementsByTagName("title"); if (titleElements.getLength() > 0) { Element titleElement = (Element) titleElements.item(0); String title = titleElement.getTextContent(); System.out.println("Title: " + title); } inputStream.close(); } }


上一篇:
下一篇:
切换中文