in reply to Updating XML while preserving formatting

You can use XML::Twig with the twig_toots and twig_print_outside_roots options:

XML::Twig->new( twig_roots => { q{elt[@id="id1"]} => sub { $_->set_tex +t( "new_val")->print} }, twig_print_outside_roots => 1, ) ->parsefile( "my_xml")

If you have control over the original XML, you may also want to have a look at pretty_print with the cvs option, which is especially designed to make XML friendly to line-oriented tools like source control systems.