updated: i should have include a little more complex xml the first time. looking at page 213 of "Learning XML", it would appear that not even rudimentery xpath expressions are handled. or... i am sadly mistaken. trying "lastChild()" and "firstChild()" yielded same results! *sigh* hello, tried to use discussion for xml::dom::lite on cpan, but no response... looking for a module that is "pure perl" that does xpath. if i have some xml fragment like:
<quotelist> <quotation style="wise" id="q4"> <source> Juan Ramon Jiminez </source> <quotation id="q5" style="political"> <source> Thomas Jefferson </source> </quotation> </quotelist>
what is the proper to way to get the "id" attribute's value? what is the proper way to get the string "political" and the string "Thomas Jefferson" returned? what i am trying:
use warnings; use strict; use Data::Dumper; use XML::DOM::Lite qw( Parser XPath ); my $doc = Parser->parseFile( '/rshome/jaw2/xml/practice.xml' ); my $result1 = XPath->evaluate( 'quotelist/quotation[@id="q5"/@style', +$doc ); print Dumper $result1; my $result2 = XPath->evaluate( '/quotelist/quotation[id="q5"]/source/t +ext()', $doc ); print Dumper $result2;
i thought i would get "Thomas Jefferson" with this. not finding enough xpath examples to know if i am even using xpath correctly. i have both "XML in a Nutshell" and "Learning XML". thanks in advance for advice and pointers.

In reply to 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.