I had to tweak it just a bit... for some reason I was getting the error Can't use global $_ in "my" at ./twig3.pl line 15, near "my $_ " and I added passing the filename as a command line variable.

#!/usr/opt/perl5/bin/perl -sw # use strict; use XML::Twig; # my $xmlfile=@ARGV; my $twig = XML::Twig->new(); $twig->parsefile($xmlfile); my $root = $twig->root; my @nodes1 = $root->get_xpath('//Holding'); for my $hold (@nodes1){ print "\nId = ".$hold->att('id')."\n"; my @nodes2 = $hold->get_xpath('Policy/KeyedValue/KeyValue'); for $_ (@nodes2){ print $_->prev_sibling_text." = "; print $_->text."\n"; } } ./twig3.pl -xmlfile=a2b9f375-51fe-41a1-86ab-069561517890.xml Id = Holding_a344e55a-1471-4c90-aa94-481b434a5b12 AccountType = UTMA_UGMA CheckIndicator = No 1035ExchangeIncluded = No SponsorName = Transamerica Id = Holding_8f6e6000-6cc5-4e7a-b5e8-3acd2ee03468 OldProductType = 401K

this will get me on my way! Thank you, you help is much appreciated. Also a note, I've discovered during this adventure that the file is an ACORD standard file https://www.acord.org/standards/downloads/Pages/PCSPublic1.aspx for what its worth. Now I just need to figure out how to dissect the sub-attributes and insert them into the XPath.

Again, thank you.


In reply to Re^4: Xpath value query by SDwerner
in thread Xpath value query by Anonymous Monk

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.