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


In reply to extract tag content from VLC webserver via XML::Rules by rainforest1155

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.