jim:

You are right that the documentation out there is a bit tough. That being said, though, here's my first XML::DOM::Lite snipper ever ;-)

use warnings; use strict; use Data::Dumper; use XML::DOM::Lite qw( Parser XPath ); my $doc = Parser->parseFile( 'test.xml' ); my $node = $doc->selectSingleNode('quotelist/quotation[@id="q5"]/sourc +e'); print $node->firstChild()->nodeValue();

This uses your XPath query (minus the @) and gets the text from 'Node' object. (See the documentation for more info on what you can do with node object.)

BTW - I used the output from the 'Data::Dumper' to confirm that the 'Thomas Jefferson' was in the output, and with that I knew the XPath was correct.

The tricky part is realising that nodes can have multiple children (apparently!)

Anyway! Hope that get things off to a good start for you!

Kurt

PS: Happy Birthday Canada!!

Updated code for requested output.


In reply to Re: trying to use XML::DOM::Lite by whereiskurt
in thread trying to use XML::DOM::Lite by jim_neophyte

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.