rkmase has asked for the wisdom of the Perl Monks concerning the following question:
So, this is one entry in a list of 10 thats produced - now, if I use this code:'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
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.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);
any words of wisdom? Thanks!foreach $subfield (@{$data->{present_response}->{record}->{datafield}- +>{subfield}}) { $gooddata=$subfield->{content}; push(@title, $gooddata); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing with XML::Simple - repeated elements will not parse correctly
by ikegami (Patriarch) on Nov 27, 2007 at 17:21 UTC |