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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |