in reply to Retrieving an XML node value with XML::DOM::Lite and XML::Parser
hthuse warnings; use strict; use XML::Twig; my $xml=<<'XML'; <Root> <A > <B>B value</B> <C> <D d_attribute="d_attribute_value">D_Value</D> </C> </A > <A> <B>B value</B> <C> <D d_attribute="d_attribute_value">D_Value</D> </C> </A> </Root> XML my $twig= new XML::Twig( pretty_print => 'indented', twig_handlers => { '/Root/A/B' => \&field_B, '/Root/A/C/D' => \&field_ +D, }, ); $twig->parse( $xml); sub field_B { my( $twig, $field)= @_; print 'Value of B is: '.$field->text."\n"; } sub field_D { my( $twig, $field)= @_; print 'Value of D is: '.$field->text."\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Retrieving an XML node value... switch to XML::Twig
by young_monk_love_perl (Novice) on Dec 20, 2013 at 08:17 UTC |