in reply to How to parse a xml file using XML::DOM??

Personally, I would use XML::DOM::XPath, locate the element through the appropriate XPath query (//signal[@sigid="3464"]) and then output its value.

Replies are listed 'Best First'.
Re^2: How to parse a xml file using XML::DOM??
by ankit.tayal560 (Beadle) on Sep 22, 2016 at 09:31 UTC

    Got your point but for some reason have to use XML::DOM only. Can you help me with that ?

      Looking at the documentation of XML::DOM, it shows the use of ->getElementsByTagName. The simplest approach would then be something like:

      my $signals = $doc->getElementsByTagName('signal'); my @by_id = grep { my $sigid= $_->getAttributeNode('sigid'); if( $sigid ) { $sigid == 3464 } else { 0 # no sigid attribute, no match } } map { $signals->item($_) } 0..$signals->getLength()-1

      I still recommend using an XPath query.