There's an advantage to XPath in that one can easily extract specific nodes that have specific attributes and get the specific component (i.e., a node in xml format or text within a tag) that one wants in a string.  Of course, you're probably right, if I knew more about what I'm doing I could work with just LibXML.  Nevertheless, with the help of the lovely and talented Miss jarich, I managed to resolve the problem, or should I say, I patched together LibXML and XPath to accomplish what I wanted.  Below is code added to the original node above that resolved the problem:

. . use XML::LibXML;# Plus the other modules above . . my $uri = "http://www.perlmonks.org/index.pl?node_id=30175&sinceunixti +me=20020820"; . # Parse out XML using LibXML to a string my $doc = $parser->parse_file($uri); my $root = $doc->getDocumentElement; my $file = $doc->toString; my $xpath = XML::XPath->new(xml=>"$file"); [...And resume the above code.]

There are three key changes here.  First, I had to change the URI address.  The uri I started with was a little messy:  I kept getting all kinds of extra HTML header stuff I couldn't skip over, causing it to crap out--I was probably doing it wrong, I admit.  Incidentally, the unixtime value should be calculated by code--I'll tend to that later.  The second key is to use the toString directive to save the matching XML tags and their text contents to $file.  The last and most significant key was to change the last line of the code shown in this post from the "filename" format directive (XML::XPath->new(filename=>$file))to the "xml" directive (XML::XPath->new(xml=>"$file")).  So, LibXML gets the XML from the PM site and then saves it to a string for XPath to read and extracts the desired nodes for standard Perl to work with.  I know this is the hard way to do it, but I'm still learning and would love for any one who so inclined to stream-line what I've done.  Otherwise, thanks for all the feedback and advice.

-Spenser

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


In reply to Re: Retrieving Remote XML Data by Spenser
in thread 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.