http://www.perlmonks.org?node_id=966187


in reply to Using Perl XML::SAX to modify XML documents

Also cross-posted from SO, an efficient solution with XML::Twig:

#!/usr/bin/perl use strict; use warnings; use XML::Twig; XML::Twig->new( twig_roots => { span => sub { $_->set_tag( 'naps +')->flush; }, expandable => sub { XML::Twig::Elt->ne +w( expanded => 'this is an expanded element')->print; }, }, twig_print_outside_roots => 1, ) ->parsefile( \*DATA); __DATA__ <?xml version="1.0" encoding="UTF-8"?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket +.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd"> <body> <wicket:panel> <form wicket:id="mvpForm"> <span>Edit Information: </span> <input type="checkbox" wicket:id="editForm"/> <span>Name: </span> <span wicket:id="name"></span> <input type="text" wicket:id="nameEdit"/> <span>Last Name: </span> <span wicket:id="lastName"></span> <input type="text" wicket:id="lastNameEdit"/> <span>DOB: </span> <span wicket:id="dob"></span> <input type="text" wicket:id="dobEdit"/> <span>Occupation: </span> <span wicket:id="occupation"></span> <input type="text" wicket:id="occupationEdit"/> <span>Gender: </span> <span wicket:id="gender"></span> <span wicket:id="genderEdit"/> <input type="submit" wicket:id="submit"/> </form> <xmltag> <expandable/> </xmltag> </wicket:panel> </body> </html>