in reply to How to remove blank lines(new lines) after modifying an xml sheet.

The code you posted has errors, and you didn't post any sample input, which makes it difficult to reproduce your problem.

I think part of the reason you're having trouble is hinted at in XML::Twig:

Pretty printing (at least using the 'indented' style) is hard to get right! Only elements that belong to the document will be properly indented. Printing elements that do not belong to the twig makes it impossible for XML::Twig to figure out their depth, and thus their indentation level.

Removing the pretty_print option seems to work for me; you could also try replacing it with keep_spaces => 1.

Otherwise, you might consider doing a second pass on the document to re-indent it after you've modified it; I'm not sure if XML::Twig will allow you to do it in a single pass, perhaps someone more versed in that module knows better.

Replies are listed 'Best First'.
Re^2: How to remove spaces after modifying an xml sheet.
by 92sai (Novice) on Jun 18, 2015 at 11:39 UTC
    removing the pretty_print option is printing the whole xml on the command line, which i dont need.
      removing the pretty_print option is printing the whole xml on the command line

      I doubt that; at least I can't reproduce it with the code sample you gave. Are you sure that's the only change you made to your code?

        yeah, now its working. Thanks a lot.