Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-26 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found