Java:Jtidy从html文本到xhtml文本的转换
我正在使用JTidy,我想给它一个字符串作为输入,而不是文件。可能吗? 我怎么能做到 这是我的代码:Java:Jtidy从html文本到xhtml文本的转换,java,html,xhtml,jtidy,Java,Html,Xhtml,Jtidy,我正在使用JTidy,我想给它一个字符串作为输入,而不是文件。可能吗? 我怎么能做到 这是我的代码: FileInputStream fis =null; String htmlFileName = "report.html"; //from html to xhtml try { fis = new FileInputStream(htmlFileName); } catch (java.io.Fi
FileInputStream fis =null;
String htmlFileName = "report.html";
//from html to xhtml
try
{
fis = new FileInputStream(htmlFileName);
}
catch (java.io.FileNotFoundException e)
{
System.out.println("File not found: " + htmlFileName);
}
Tidy tidy = new Tidy();
tidy.setShowWarnings(false);
tidy.setXmlTags(false);
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setXHTML(true);//
tidy.setMakeClean(true);
Document xmlDoc = tidy.parseDOM(fis, null);
try
{
tidy.pprint(xmlDoc,new FileOutputStream("report.xhtml"));
}
将
文件输入流
替换为从字符串
读取的流,例如
try
{
fis = new ByteArrayInputStream(string.getBytes());
} catch (java.io.IOException e) {
System.out.println("Error reading string");
return;
}