0

So what I'm doing is, I'm finding and deleting some tags from an XML. After deleting, those tags are getting replaced by blank space, which actually ain't effecting the XML but it can cause problem when I delete a large number of tags.

Any working way to achieve this?

Thanks in Advance.

Here is the link of the answer I found here but it's not working

Community
  • 1
  • 1
Amrit Kr Lama
  • 109
  • 2
  • 11
  • Welcome to Stack Overflow! Please review our [SO Question Checklist](http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist) to help you to ask a good question, and thus get a good answer. – Joe C Feb 25 '17 at 12:31

1 Answers1

0

This should work:

public static void main(String[] args) {

    Scanner file;
    PrintWriter writer;

    try {

        file = new Scanner(new File("src/myXml.xml"));
        writer = new PrintWriter("src/myXml2.xml");

        while (file.hasNext()) {
            String line = file.nextLine();
            if (!line.isEmpty()) {
                writer.write(line);
                writer.write("\n");
            }
        }

        file.close();
        writer.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Alicia Sykes
  • 5,997
  • 7
  • 36
  • 64