Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Help with Parsing XML output

by runrig (Abbot)
on Aug 12, 2014 at 17:06 UTC ( [id://1097152]=note: print w/replies, xml ) Need Help??


in reply to Help with Parsing XML output

Here's an XML::Rules solution, though I'm not sure if there may or may not be more than one label per category, or more than one keyword per keywords. I'm assuming "may not", but easy enough to fix if "may" (I would add 'as array no content' rules for label and keyword, and then assume arrays in the parent node's code):
use strict; use warnings; use XML::Rules; my $xml = <<XML; <?xml version="1.0" encoding="UTF-8"?> <results> <url>--removed--</url> <language>english</language> <text>---removed---</text> <taxonomy> <category> <label>/vehicle brands/jeep</label> </category> <category> <label>/travel</label> </category> </taxonomy> <keywords> <keyword> <text>rear extended bumpstops</text> </keyword> </keywords> </results> XML my @rules = ( category => sub { my $r = $_[1]; print "Category: $r->{label}\n"; }, keywords => sub { my $r = $_[1]; print "Keywords: $r->{text}\n"; }, keyword => 'pass no content', _default => 'content', ); my $xr = XML::Rules->new( rules => \@rules ); $xr->parse($xml);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-20 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found