Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to parse a xml file using XML::DOM??

by Corion (Patriarch)
on Sep 22, 2016 at 09:23 UTC ( [id://1172356]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1172356]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-19 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found