Re: XML::Parser, regex, or ??
- From: "Sarah" <Hersheys98@xxxxxxx>
- Date: 3 Dec 2006 18:16:25 -0800
I must be doing something wrong. It might have to do with the way I am
trying to do the input. Sorry if my code is totally ridiculous. I am
quite a beginner. Here is my code so far:
#!/usr/local/bin/perl -w
use strict;
use LWP;
my $ua = new LWP::UserAgent;
my $response =
$ua->get('http://mediaservices.myspace.com/services/media/musicplayerxml.ashx?b=79777730');
my $content = $response->content;
# use module
use XML::Simple;
use Data::Dumper;
# create object
$xml = new XML::Simple;
print "Content-Type: application/xml\n\n";
# read XML file
$data = $xml->XMLin($content);
# print output
print Dumper($data);
Where am I going wrong? Thank you so much for your help. :o )
Sarah
DJ Stunks wrote:
Sarah wrote:
Hi -
Hi!
I want to go to a certain .ashx
url and pull out the the number that appears in the CDATA between
<totalplays> and </totalplays>. Should I be using XML::Parser or
should I be figureing out a regular expression for this?
whenever possible I suggest using XML::Simple over XML::Parser. Only
if you need stream based (rather than tree based) processing, or if you
need more power over how the parser operates should you go with the
more complex XML::Parser.
one should almost never try to write a regular expression to parse XML
or HTML.
The source code for the .ashx page I am trying to parse is:
<?xml version="1.0" encoding="iso-8859-1"?>
<profile>
<timestamp><![CDATA[1165003930]]></timestamp>
<name><![CDATA[Omaha]]></name>
<playstoday><![CDATA[0]]></playstoday>
<downloadedtoday><![CDATA[0]]></downloadedtoday>
<totalplays><![CDATA[8272]]></totalplays>
<autoplay><![CDATA[2]]></autoplay>
<allowadd><![CDATA[1]]></allowadd>
<playlist><song bsid="21773411" title="Unappreciated" songid="11709799"
plays="364" comments="11709799" rate="11709799" downloadable=""
imagename="http://www.someurl.jpg" imagedesc="Cherish -
Unappreciated<br>2006 Capitol"
filename="iQpqKbTHhxD6nnHTrMXKEYM0J+g5udpwP8TiHpkg4xXP59oqhpc44q3oVL6NUdd+q1YOYVTx2Qw8Qj67R0lDPUaLwX+/eByv/EWxtcUe7wg="
url="http://www.someurl.ashx?i=MIGdBgorBgEEAYI3WAOkoIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECB5NzL5vs%2bPgBBBi3gOcOpyzL7dNA7PUPXBlBFCL9Gcb%2f4U7Y1f4wRMr4zD4MfmxUXeJkKIa06IsC4lz2GBvWsse3T0%2fOGioo6odeaaA09%2bYX%2bKeX4lpzlqSVJeIHZACWTuYY03Sm09Arc7eUw%3d%3d"
lyrics="" purl="" durl="http://www.someurl.mp3"
token="0Q+uaMY0E0C9LlTFetCt3GyYf2O57O58XD//PBofNqPdA/NWnX+8joBR/QeIeeO+44EX5+N85zNkodtckgWsYRRVd6/M34v/KI27it1jaPw="/>
</playlist>
</profile>
XML::Simple will pull the information from this source without any
problems whatsoever.
good luck. re-post if you need more clarification.
-jp
.
- Follow-Ups:
- Re: XML::Parser, regex, or ??
- From: DJ Stunks
- Re: XML::Parser, regex, or ??
- References:
- XML::Parser, regex, or ??
- From: Sarah
- Re: XML::Parser, regex, or ??
- From: DJ Stunks
- XML::Parser, regex, or ??
- Prev by Date: Re: Checking for infinite loops
- Next by Date: system, ``, exec... hangs
- Previous by thread: Re: XML::Parser, regex, or ??
- Next by thread: Re: XML::Parser, regex, or ??
- Index(es):
Relevant Pages
|