Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to Parse XML output?

by rjt (Chaplain)
on Mar 12, 2013 at 23:37 UTC ( #1023078=note: print w/ replies, xml ) Need Help??


in reply to How to Parse XML output?

There are many CPAN modules which can help you. For your first foray into simple XML parsing, I'd recommend XML::Simple. Despite being "simple", it still tends to do what I need most of the time.

use 5.014; use XML::Simple; my $xmls = XMLin($xml_string); say $_->{AttrValue} for grep { $_->{AttrName} eq 'ref_num' } @{$xmls->{Attributes}->{Attribute}};

$xmls is just an ordinary HASH ref; it's usually instructive to print it out with Data::Dump, Data::Dumper or similar:

use Data::Dump; dd $xmls;


Comment on Re: How to Parse XML output?
Select or Download Code
Re^2: How to Parse XML output?
by powermonk (Initiate) on Mar 13, 2013 at 16:59 UTC
    I tired it, but its not working. Below is what I am doing. my $xml_string= $result->result; //Store return value of webservices function. my $tkt= $_->{AttrValue} for grep { $_->{AttrName} eq 'ref_num' } @{$xmls->{Attributes}->{Attribute}}; print $tkt Not able to capture value.
      Finally Got it. Was able to extract it using XML::LibXML by passing the string. Thanks all for your valuable help.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-04-19 03:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (477 votes), past polls