0

我在手机上存储了一个 html 文件,我想用 HtmlCleaner 清理它并查看输出结果。这是我的代码:

public void cleanHtml() throws IOException{
    HtmlCleaner cleaner = new HtmlCleaner();

    CleanerProperties props = cleaner.getProperties();

    TagNode node = cleaner.clean(htmlToClean);

    new PrettyXmlSerializer(props).writeToFile(node, "4c.xml");
}

这没有任何作用。我想在手机上的某处查看 .xml 或已清理的 .html 文件。

这是 htmlToClean 变量:

htmlToClean = new File(Environment.getExternalStorageDirectory().getPath() + "/Android/data/com.whizzapps.stpsurniki/4c.html");
4

1 回答 1

0

像这样解决它:

private class cleanHtml extends AsyncTask<Void, Void, Void>{

    @Override
    protected Void doInBackground(Void... arg0) {
        try {
            HtmlCleaner cleaner = new HtmlCleaner();
            String url = "https://www.easistent.com/urniki/263/razredi/16515";
            TagNode node = cleaner.clean(new URL(url));
            CleanerProperties props = cleaner.getProperties();
            String fileName = Environment.getExternalStorageDirectory().getPath() + "/Android/data/com.whizzapps.stpsurniki/cleaned.html";
            new PrettyXmlSerializer(props).writeToFile(node, fileName, "utf-8");
            Log.i("TAG", "AsyncTask done!");
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}
于 2013-11-03T21:13:59.870 回答