in reply to Re: inserting a tag before a string
in thread inserting a tag before a string
> I originally tried to have two XML documents open and copy/paste items from one into the other
Well, possible it's possible, not beauty (and I added some spaces..;) but..
perl -MXML::Twig -e "BEGIN{$f=shift @ARGV} map{ XML::Twig->new(twig_handlers => { 'newitems/book' => sub { push @ +content, $_; $_->cut }})->parsefile($_) }@ARGV; XML::Twig->new(pretty_print=>'indented',twig_handlers => {'catalog' => sub {foreach my $content ( @content ) {$content->paste( last_child +=> $_ );}}})->parsefile($f)->flush " current_catalog.xml new_items.xml
L*
PS updated, obfuscated and shortened
perl -MXML::Twig -e "map{$t=XML::Twig->new(twig_handlers=>{$s?('catalo +g'=>sub{foreach$c(@c){$c->paste(last_child=>$_)}}):('newitems/book'=> +sub{push@c,$_;$_->cut})})->parsefile($_);$s++;}@ARGV;$t->flush" newb +ook.xml catalog.xml
|
|---|