Hi perl monks. I have an XML file as below, storing attributes of a list of files.
<file> <name>test.doc</name> <userprop> <nameprop>Effective Date</nameprop> <valueprop>16-Dec-2003</valueprop> </userprop> <userprop> <nameprop>Owner</nameprop> <valueprop>Adrian.Johnston</valueprop> </userprop> <userprop> <nameprop>Version</nameprop> <valueprop>v1.3</valueprop> </userprop> </file> <file> ... </file>
So if I would require all the files with version "v1.3", I would have to extract all "nameprop" nodes as below, and if the string is "Version", i'll get the equivalent string of valueprop and then do a comparison.
my $nodeset = $xpath->find('//file/userprop/nameprop'); ... $valu_node = $xpath->find('../valueprop',$node)->get_node(1);
However, if the XML for userprops was stored as attributes as below :
<userprop name="Version">v1.3</userprop>
Then, I could have taken easier XPath search of :
my $nodeset = $xpath->find('//file/userprop/[@name='v1.3]');
to derive all the version nodes. And then if they are "v1.3", I print out the file name. So qn is, is there any simple way to use XPath if my XML format is using sub-elements for "userprop", as in the first listing above. Thanks.

In reply to XPath search qn by Justudo

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.