Re: XML::Parser, regex, or ??



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&lt;br&gt;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

.



Relevant Pages

  • Re: Regex Replace Help
    ... It does the replace in the entire xml file. ... And last but not the least i collect all answers posted to my Regex ... I just became aware of something similar called Regular Expression ... Jesse Houwing ...
    (microsoft.public.dotnet.framework)
  • Regular Expression help
    ... As I parse a file I need to pull an IP ... Now I thought a regular expression would be the ... entire string backwards and testing whether I have a number or a char, ...
    (comp.lang.ruby)
  • Re: XML::Parser, regex, or ??
    ... url and pull out the the number that appears in the CDATA between ... should I be figureing out a regular expression for this? ... one should almost never try to write a regular expression to parse XML ... XML::Simple will pull the information from this source without any ...
    (perl.beginners)
  • Re: Regex Replace Help
    ... This is a problem with a larger .xml file in which xx&xx is creating a ... And last but not the least i collect all answers posted to my Regex queries ... I'll try to play with it later today but no promises. ... Will someone please help with the Regular Expression. ...
    (microsoft.public.dotnet.framework)
  • Re: Find instance in a string
    ... > I'm looking to find in a long string an instance of 4 numbers in a row, ... > pull out those numbers. ... You want a regular expression, ... I ran into the problem that putting ^ in has a different meaning. ...
    (microsoft.public.dotnet.languages.vb)