in reply to Re^4: xml::twig delete element
in thread xml::twig delete element
This should do more or less what you want:
use strict; use warnings; use XML::Twig; my %self2pnam; # Self => pnam for all color elements my $twig=XML::Twig->new( # create self2pnam twig_handlers=>{ color => sub { $self2pnam{$_- +>att('Self')}= $_->att( 'pnam'); } }, pretty_print => 'indented', ); $twig->parse(\*DATA); # now we can process the content elements foreach my $content ($twig->root->children( 'content')) { my $box= $content->prev_elt( 'box[@type="text"]'); $content->set_tag( 'updated_tag') ->del_atts ->set_att( Color => $self2pnam{$box->att( 'frameColorID')} +) ; } $twig->print; __DATA__ <document> <root> <box type="text" cont="text" textflowid="rc_u5035" frameColorID="ua +5"/> </root> <content type="text" Self="rc_u5035" id="rc_u5035"/> <header>h3</header> <meta> <color type="colr" clmd="prss" clsp="CMYK" clvl="4_D_0_D_15_D_50_D_0 +" ovrd="norm" atcs="nasp" atvl="0" pnam="Color 04-15M/50Y" edbl="t" r +mbl="t" pvis="t" swID="1f01" Self="uce"/> <color type="colr" clmd="prss" clsp="CMYK" clvl="4_D_0_D_10_D_40_D_0 +" ovrd="norm" atcs="nasp" atvl="0" pnam="Color 05-10M/40Y" edbl="t" r +mbl="t" pvis="t" swID="1f01" Self="ua5"/> </meta> </document>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: xml::twig delete element
by Selvakumar (Scribe) on Oct 14, 2009 at 06:49 UTC | |
by mirod (Canon) on Oct 14, 2009 at 10:21 UTC | |
by Selvakumar (Scribe) on Oct 14, 2009 at 10:59 UTC |