in reply to creating an xml file from perl

Instead of
print FIL "<categoryName>\n";
you'd use
print FIL "<site>\n";

Instead of
print FIL "</pics>\n";
you'd use
print FIL "</site>\n";

Instead of
print FIL "<pic$t name=\"$nfile\"></pic$t>\n";
you'd use

use URI::Escape qw( uri_escape ); my $escaped_file = $nfile; # Convert the file name to a URL. $escaped_file = uri_escape($nfile); # Escape the URL for use in an HTML attribute. #uri_escape already removes & and ". #$escaped_file =~ s/&/&amp;/g; #$escaped_file =~ s/"/&quot;/g; print FIL "<item id=\"$t\" name=\"$escaped_file\" />\n";

btw, it checks for .jpg in lowercase. You may want to replace
substr($filename, length($filename)-4, 4) eq ".jpg"
with
lc(substr($filename, length($filename)-4, 4)) eq ".jpg"
or the simpler
lc(substr($filename, -4)) eq ".jpg"
in case file is named SOMETHING.JPG.

Update: Added uri escaping.

Replies are listed 'Best First'.
Re^2: creating an xml file from perl
by decerebrate (Initiate) on Apr 13, 2005 at 23:55 UTC

    thank you so much.

    when i replace with this:

    my $escaped_file = $nfile; $escaped_file =~ s/&/&amp;/g; $escaped_file =~ s/"/&quot;/g; print FIL "<item id="$t" name=\"$escaped_file\" />\n";

    i get a server error

      I forgot to escape some of the quotes in the print statement. Fixed:

      my $escaped_file = $nfile; $escaped_file =~ s/&/&amp;/g; $escaped_file =~ s/"/&quot;/g; print FIL "<item id=\"$t\" name=\"$escaped_file\" />\n";

      What's the server error? My guess is that the server is complaining that it can't find the files, because you are not including the correct path to the file.

      the lowliest monk

Re^2: creating an xml file from perl
by polettix (Vicar) on Apr 14, 2005 at 14:01 UTC
    Escaping would be safer using URI::Escape:
    use URI::Escape; my $escaped_file = uri_escape($nfile);

    Flavio (perl -e "print(scalar(reverse('ti.xittelop@oivalf')))")

    Don't fool yourself.
      Shoot, I forgot about that. Actually, it needs to be URI escaped and HTML value escaped. However, since uri_escape removes '"' and '&' by default, HTML value escaping is a no-op.