I am trying to read a txt file with contents that look like this:
<LI><A HREF="http://www.mysite.com/cgi-bin/viewnews.cgi?category=1&id= +1265624320"><FONT COLOR="#000000" SIZE="-1" FACE="arial">Test headlin +e </FONT></A></FONT><BR> <LI><A HREF="http://www.mysite.com/cgi-bin/viewnews.cgi?category=1&id= +1264624826"><FONT COLOR="#000000" SIZE="-1" FACE="arial">Test headlin +e 2</FONT></A></FONT><BR> <LI><A HREF="http://www.mysite.com/cgi-bin/viewnews.cgi?category=1&id= +126j624329"><FONT COLOR="#000000" SIZE="-1" FACE="arial">Test headlin +e 3</FONT></A></FONT><BR>
I'm trying to write a bare bones xml feed with what I read in, after stripping some tags. I use this:
#!/usr/local/bin/perl use LWP::Simple; #################### # STATIC VARIABLES # #################### $original_include = "/usr/www/users/me/articles/1view.h"; $outfile = "/usr/www/users/me/test.rss"; open (FILE, $original_include) || die "couldn't open the file!"; @news = <FILE>; close(FILE); open(NEWSFEED, ">$outfile") || die "Cannot Open $outfile"; print NEWSFEED<<TEXT; <?xml version="1.0" encoding="iso-8859-1"?> <rss version="0.91"> <channel> <title>Test</title> <link>http://www.mysite.com</link> <description> Test </description> <language>en-us</language> <image> <title>Test</title> <url>http://www.mysite.com/</url> <link>http://www.mysite.com/icon.jpg</link> </image> TEXT foreach $news_include (@news) { $news_include =~ s/<LI>/<item><link>/gi; $news_include =~ s/<FONT COLOR=\"\#000000\" SIZE=\"-1\" FACE=\"arial\" +>/<\/link><title>/gi; $news_include =~ s/<\/FONT><\/A><\/FONT><BR>/<\/title><\/item>/gi; print NEWSFEED<<TEXT; $news_include TEXT } #end foreach $news_include (@news_include) print NEWSFEED"</channel>"; print NEWSFEED"</rss>"; close(NEWSFEED); system("chmod 0777 $outfile");
All that gets printed to the xml file is this:
<?xml version="1.0" encoding="iso-8859-1"?> <rss version="0.91"> <channel> <title>Test</title> <link>http://www.mysite.com</link> <description> Test </description> <language>en-us</language> <image> <title>Test</title> <url>http://www.mysite.com/</url> <link>http://www.mysite.com/icon.jpg</link> </image>
I'm sure I'm missing something here.

In reply to Help reading file, stripping tags, writing new file by htmanning

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.