Forum Moderators: coopster & phranque

Message Too Old, No Replies

Problems with XML feed and perl

         

dawlish

3:53 pm on May 6, 2003 (gmt 0)

10+ Year Member



Hi,

I am using a script below which I paid a web developer to write for me as I'm predominantely a designer with html skills and my knowledge of perl and xml is very limited.

The script processes an xml feed from another site and creates a cache file.

However when the xml is cached the code ' is stored instead of an apostrophe and as a consequence this is displayed on the site when the script is called.

For example "John's Performance" is displayed as "John&apos;s Performance". The apostrophe tends to occur in the <event_desc></event_desc>.

I'd be really grateful if anyone could advise what change I need to make to the script below in order for it to replace &apos; with a '.

I've done a search on google and it seems that &apos; is used in xml to denote and apostrophe but is not supported in html.

I would ask my developer to fix, but he is very expensive and said it would cost £50 to fix. Is this reasonable?

#!/usr/local/bin/perl -w

use strict;
use CGI qw(:all);
#use Fcntl qw(:flock);
use LWP::Simple qw(get);

my $xml_url = "http://www.domain-name.com/cgi-bin/search.exe&chan=xml";
my $newscache = "cache.xml";
########################################
# enter number of articles to include
my $howmanyarticles = "60";

########################################
# write the cache file or
# if the cache file is older than 1 hour
# then re-write it.

#get_lock();
if ((not -e $newscache) or (-M $newscache > .5)) { # (not -e) if the cache file doesn't exist, -M gives the modification time since creation, 1 is 1 day, 0.04 is about 1 hour.
my $newsdoc = get($xml_url);# uses the LWP module "get" function to get the XML file.
if (defined $newsdoc) {
open (CACHEFILE, ">$newscache") ¦¦ die "Writing to Cache : $!";
print CACHEFILE $newsdoc;
close (CACHEFILE);
}
}
#release_lock();

########################################
# now print the contents of the XML file

print header;
print "<table width=\"100%\" align= center border=\"0\" cellpadding=\"4\" cellspacing=\"0\">";

open (CF, "$newscache") ¦¦ die "Unable to open $newscache : $!";
my ($eventname, $eventvenue);
my $counter =0;
while (<CF>) {
if (m,<event_desc>(.*)</event_desc>,) {
$eventname = $1;
}
if (m,<venue_desc>(.*)</venue_desc>,) {
$eventvenue = $1;

}
if (m,<crypto_block>(.*)</crypto_block>,) {
print "
<tr>

<td valign=\"top\"><a href=\"$1\">$eventname</a></td><td>$eventvenue</td>
";
$counter++;
last if $counter == $howmanyarticles;
}
}
close(CF);

print "
<tr>
<td width=\"100\%\" colspan=\"4\" height=\"10\"></td>
</tr>
</table>
";
# END

jatar_k

1:29 am on May 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



oh, c'mon someone must know the answer ;)

idiotgirl

2:13 am on May 7, 2003 (gmt 0)

10+ Year Member Top Contributors Of The Month



if (m,<event_desc>(.*)</event_desc>,) {
$eventname = $1;
$eventname =~ s/&apos;/'/g;
}
if (m,<venue_desc>(.*)</venue_desc>,) {
$eventvenue = $1;
$eventvenue =~ s/&apos;/'/g;
}

That worked when I tested it in a short test script.

dawlish

8:23 am on May 7, 2003 (gmt 0)

10+ Year Member



Brilliant. Works perfectly!

idiotgirl

1:06 pm on May 7, 2003 (gmt 0)

10+ Year Member Top Contributors Of The Month



It may not be the best or shortest way, but I can't believe someone else with an intimate familiarity with the script would charge that much to add two short lines of code. hmmm...