Lately, I've been attempting to teach myself XML.  I've almost completely read "Learning XML" (O'Reilly) and "XML Visual Quickstart" (Peachpit).  I've read much of O'Reilly's new book, "Perl & XML"--a very well written and useful book on the subject, incidentally.  I've been reading tutorials and articles and postings and so forth all over the web (include PM using SuperSearch).  I'm worn out on the subject, but I am starting to put things together in my head and on my computer.  However, I need a little help with one of my learning exercises I created for myself.

Below is a simple script I whipped together to experiment with the Perl module, XPath.  The script reads in an XML text file which I copied from the Newest Nodes XML Generator link.

#!/usr/bin/perl use CGI; use XML::XPath; use XML::XPath::XMLParser; my $q = new CGI; my $file = 'newmonk_perlquestions.xml'; my $xpath = XML::XPath->new(filename=>$file); # Find only new perl questions my $nodeset = $xpath->find('//NODE[@nodetype="perlquestion"]'); # Create web page to display matching nodes print $q->header( -type=>'text/html'), $q->start_html(-title=>'New Perl Questions'), "<b>New Perl Questions</b>", $q->br, $q->hr, foreach $node($nodeset->get_nodelist) { $nodeinfo = XML::XPath::XMLParser::as_string($node); $nodeinfo =~ /node_id=\"(\d+)/; print $q->a({-href=>"http://www.perlmonks.org/index.pl?node_id=$1"}, $nodeinfo), $q->br; } print $q->end_html; exit;

This works fine.  However, I thought it would be cool to have $file point to the PM site address rather than a copy saved to my server.  When I replace the $file declaration line with the following:

my $file = "http://www.perlmonks.org/index.pl?node=newest%20nodes%20xm +l%20generator";

I get a "Cannot open file..." error message.  I can open it manually in my web browser, but not through this Perl script.  I know I'm missing something conceptually, as well as specifically.  Can any one help me with this exercise?


-Spenser

That's Spenser, with an "s" like the detective.


In reply to Using XPath to Retrieve Remote XML Data by Spenser

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.