I have a large xml output file with data that repeats for each entity it comes across, like below:
'timeResult' => [ { 'success' => 'false', 'connection' => 'eth1', 'portResponse' => 'OK', 'ns5:snmpType' => { 'cd5:targetType' => 'eth', 'name' => 'string1', 'cd5:protocol' => 'udp', }, 'localTime' => '2008-12-04T' }
The section above repeats about 10 times per file (once for each host tested). I have successfully parsed the beginning section (getting the values of success, localTime, and portResponse) with the code below, but I can't figure out how to get to the 'snmpType' area, and put targetType, name and protocol into variables. Can someone help me to figure out what I need to do? thank you-
use XML::XPath; # ## create object my $xml = XML::XPath->new(filename => '/sources/sample.xml'); # foreach my $row ($xml->findnodes('/touchResult/scanResult')) { my $success = $row->find('success')->string_value; my $portResponse = $row->find('portResponse')->string_value; my $localTime = $row->find('localTime')->string_value; ....; }

In reply to parsing large xml file with XML::PATH by ktpmm5

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.