HTML文件转换成XML文件
HTML文件轉換成XML文件
//设置tidy
Tidy tidy = new Tidy();
// Set file for error messages
tidy.setErrout(new PrintWriter(new FileWriter(errOutFileName), true));
// Tell Tidy to convert HTML to XML
tidy.setXmlOut(true);
tidy.setInputEncoding("UTF-8");
FileInputStream in0 = new FileInputStream( tmpNewFile );
FileOutputStream out0 = new FileOutputStream(outFileName);
//Convert files
tidy.parse(in0, out0);
//Clean up
in.close();
out.close();
tmpNewFile.delete(); // 删除临时文件
} catch (IOException e) {
System.out.println(this.toString() + e.toString());
}
}
public static void main(String[] args) {
/*
* Parameters are:
* URL of HTML file
* Filename of output file
* Filename of error file
*/
String u="http://www.baidu.com/";
String o="index.xml";
String e="error.xml";
xml t = new xml(u, o, e);
t.convert();
System.out.println("OK!");
}
}