in reply to Retrieving an XML node value with XML::DOM::Lite and XML::Parser

As TIMTOWTDT me too I suggest to switch module: to XML::Twig. As noted by tangent you need a Root node, and you need the equal sign between attributes and their values.

I'm not an expert, but please look at the linearity of handlers (subs called during the parsing, called when an xpath match) usage:
use 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"; }
hth
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

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

    Thank you very much, it works ! I used XML::Twig which seems to fit better with the XML file I'm parsing.