Spenser has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using XPath to Retrieve Remote XML Data
by the pusher robot (Monk) on Aug 26, 2002 at 22:26 UTC | |
|
Re: Using XPath to Retrieve Remote XML Data
by lestrrat (Deacon) on Aug 26, 2002 at 22:34 UTC | |
|
CGI to display newest questions only
by lestrrat (Deacon) on Aug 29, 2002 at 05:50 UTC | |
|
Retrieving Remote XML Data
by Spenser (Friar) on Aug 27, 2002 at 20:00 UTC | |
by lestrrat (Deacon) on Aug 28, 2002 at 00:52 UTC | |
|
Re: Retrieving Remote XML Data
by Spenser (Friar) on Aug 28, 2002 at 17:01 UTC | |
by lestrrat (Deacon) on Aug 28, 2002 at 22:10 UTC |