rainforest1155 has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I'm new to Perl and was trying to extract the contents of a specific tag from my VLC webserver xml status page. Here's an example of the XML (I removed a couple of tags in the sections I'm not interested in to keep things shorter:
<root> <fullscreen>0</fullscreen> <audiodelay>0</audiodelay> <apiversion>3</apiversion> <time>1</time> <volume>256</volume> [...] <information> <category name="meta"> <info name="title">CINEMIX</info> <info name="filename">CINEMIX</info> <info name="genre">Soundtracks Classical New Age</info> <info name="now_playing">John Williams-Losing E.T.-E.T. The Extr +a-Terrestrial: 20th Anniversary</info> </category> <category name="Stream 0"> <info name="Bitrate">192 kb/s</info> [...] </category> </information> <stats> <lostabuffers>2</lostabuffers> [...] </stats> </root>
What I'm interested in is just the contents of the <info name="now_playing"> tag which contains artist, title and album.
I already have some code that does return all the <info> tags but I'm not sure how to specifically return just the "now_playing" tag content.
This is the code I managed to hack together so far using parts of code I found in the monastry:
#!/usr/bin/perl use strict; use XML::Rules; use LWP::Simple; my $streaminfo = get("http://127.0.0.1:8080/requests/status.xml"); my $parser = XML::Rules->new( stripspaces => 7, rules => { info => sub { print "$_[1]->{_content}\n"; return; }, } );
I haven't been able to figure out how to filter the results to just the portion I'm interested to. I did look at the XML::Parser docs on cpan.org and have the feeling it's in there, especially the home / office phone example that's touched on in the synopsis, but I can't translate that into any working code.
Thanks for any assistance you can offer.
Sebastian
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: extract tag content from VLC webserver via XML::Rules
by vagabonding electron (Curate) on Jun 25, 2013 at 11:32 UTC | |
by rainforest1155 (Initiate) on Jun 25, 2013 at 16:05 UTC | |
by rainforest1155 (Initiate) on Jun 25, 2013 at 17:12 UTC | |
by vagabonding electron (Curate) on Jun 25, 2013 at 18:19 UTC | |
by mcoblentz (Scribe) on Jun 26, 2013 at 15:38 UTC | |
by rainforest1155 (Initiate) on Jun 27, 2013 at 11:13 UTC | |
|
Re: extract tag content from VLC webserver via XML::Rules
by hdb (Monsignor) on Jun 25, 2013 at 09:42 UTC | |
by Anonymous Monk on Jun 25, 2013 at 09:47 UTC |