I looked in the archives and found a couple of posts that were similar to what I was looking for, but not quite what I needed. I'd love if someone could explain why this works for one, but not the other - First things - Data:
'record' => [ { 'xmlns' => 'http://www.loc.gov/MARC21/slim', 'xmlns:xsi' =>something', 'xsi:schemaLocation' => somehtml', 'datafield' => [ { 'ind1' => ' ', 'ind2' => ' ', 'subfield' => [ { 'content' => '0047-3936', 'code' => 'a' } ], tag' => '022' }, { 'ind1' => '1', 'ind2' => '0', 'subfield' => [ { 'content' => 'more content here', 'code' => 'a' } ], 'tag' => '245' } ] }, repeat this structure entry x10
So, this is one entry in a list of 10 thats produced - now, if I use this code:
my $xml = new XML::Simple (ForceArray => 1, KeyAttr=>[]); $data = $xml->XMLin($dirtyxml); foreach $record(@{$data->{present_response}->{record}}) { $gooddata=$record->{xmlns}; push(@title, $gooddata); } foreach (@title) { $list = $list."<p>".$_."</p>"; } my $output = "<p>".$list."</p>"; return($output);
I can easily pull and display the values of {xmlns} for each entry, but attempting to pull {datafield}->{subfield}->{content} (notice there can be 2 or more per entry), using the same method, I get nothing - eg.
foreach $subfield (@{$data->{present_response}->{record}->{datafield}- +>{subfield}}) { $gooddata=$subfield->{content}; push(@title, $gooddata); }
any words of wisdom? Thanks!

In reply to Parsing with XML::Simple - repeated elements will not parse correctly by rkmase

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.