javaandroidhtmlcleaner

Clean html with HtmlCleaner


I have a html file stored on the phone and I want to clean it with HtmlCleaner and see the output result. Here's my code:

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");
}

This doesn't do anything. I want to see the .xml or cleaned .html file somewhere on my phone.

This is htmlToClean variable:

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

Solution

  • Solved it like this:

    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;
        }
    }