in reply to Re^2: XML tag replace
in thread XML tag replace
Learning Perl would be a good book to start with. You may find that the monastery's Tutorials section is good for a quick start.
Here's a starting point for your XML manipulation using XML::TreeBuilder:
use strict; use warnings; use XML::TreeBuilder; my $xml = <<XML; <author-group> <auth> </auth> <auth> </auth> <auth> </auth> <aff> </aff> <aff> </aff> <corres id="cor1"> </corres> </author-group> XML my $root = XML::TreeBuilder->new (); $root->parse ($xml); for my $group ($root->look_down ('_tag', 'author-group')) { my @auths = $group->look_down ('_tag', 'auth'); my $newRoot = HTML::Element->new ('xxx'); $_->detach () for @auths; $newRoot->push_content (@auths); $group->unshift_content ($newRoot); } print $root->as_XML ();
Prints:
<author-group><xxx><auth> </auth><auth> </auth><auth> </auth></xxx> <aff> </aff> <aff> </aff> <corres id="cor1"> </corres> </author-group>
Still pretty trivial eh.;)
|
|---|