use strict; use XML::Simple; my $org = <<'XML'; XML # parse the input string my $root = XMLin ($org, KeepRoot => 1, ); # Insert the element $root->{FILER}{LOCATION}{name} = '1stFloor'; # Dump the result print XMLout ($root, RootName => undef); #### #### use strict; use XML::TreeBuilder; my $org = <<'XML'; XML # parse the input string my $root = XML::TreeBuilder->new (); $root->parse ($org); # Insert the element my $ins = XML::Element->new ('LOCATION', name => '1stFloor'); $root->push_content ($ins); # Dump the result print $root->as_XML (); #### #### use strict; use XML::Twig; my $org = <<'XML'; XML # parse the input string my $root = XML::Twig->new (); $root->parse ($org); # Insert a new element my $ins = XML::Twig::Elt->new ('LOCATION', {name => '1stFloor'}); $ins->paste ('last_child', $root->root ()); # Dump the result $root->print (); ####