Skip to content
Advertisement

How to remove extra empty lines from XML file?

In short; i have many empty lines generated in an XML file, and i am looking for a way to remove them as a way of leaning the file. How can i do that ?

For detailed explanation; I currently have this XML file :

JavaScript

And i use this Java code to delete all tags, and add new ones instead :

JavaScript

After executing this method a number of times i get an XML file with right results, but with many empty lines after the “paths” tag and before the first “path” tag, like this :

JavaScript

Anyone knows how to fix that ?

——————————————- Edit: Add the getXMLFile(…), saveXMLFile(…) code.

JavaScript

Advertisement

Answer

I was able to fix this by using this code after removing all the old “path” nodes :

JavaScript

This will remove all the generated empty spaces in the XML file.

Special thanks to MadProgrammer for commenting with the helpful link mentioned above.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement