in reply to Re^2: XML::Twig correct parent, xpath filter
in thread XML::Twig correct parent, xpath filter
#!/usr/bin/perl use warnings; use strict; use XML::Twig; my $xmlFile = 'demo.xml'; my $t = XML::Twig->new( keep_atts_order => 1, pretty_print => 'indented_a', twig_handlers => { 'myconfig/myobj/myattributes/attribB' => \ +&getfoo, }, ); $t->parsefile($xmlFile); $t->print; sub getfoo { my ($t, $e) = @_; my $id = $e->parent->parent->first_child_text('uniqueName'); if ('objB' eq $id) { $e->set_text(' NEW '); } }
For comparison, the same task in XML::XSH2:
open demo.xml ; set /myconfig/myobj[uniqueName='objB']/myattributes/attribB 'NEW' ; save :b ;
|
|---|