Parse html with jsoup and remove the tag block

后端 未结 4 2008
傲寒
傲寒 2021-01-05 06:00

I want to remove everything between a tag. An example input may be

Input:


  start
  
delete from below
4条回答
  •  独厮守ぢ
    2021-01-05 06:09

    Try this code :

    String data = null;
        BufferedReader br = new BufferedReader(new FileReader("e://XMLFile.xml"));
        StringBuilder builder = new StringBuilder();
        while ((data = br.readLine()) != null) {
            builder.append(data);
        }
        System.out.println(builder);
        String replaceAll = builder.toString().replaceAll("
    ", ""); System.out.println(replaceAll);

    I have read the input XML from a file and stored it in a StringBuilder object by reading it line by line, and then replaced the entire tag will empty string.

提交回复
热议问题