abullen has asked for the wisdom of the Perl Monks concerning the following question:

Sorry, confused, trying to parse a complicated XML data structure. Dump from Data::Dumper:

$VAR1 = {
          'OneUploadedFile' => [
                               {
                                 'FirstParagraphOfText' => '.Illinois Web Links for Project Next Generation Abraham Lincoln Pr
esidential Library Art Edventure! (etc. etc.).',
                                 'InterimTrigramStoragePath' => {},
                                 'InterimDocStoragePath' => {},
                                 'InterimBigramStoragePath' => {},
                                 'ChecksumResult' => '01331d9ac99bfd620183e122a256a901',

Question to all. How do get the value of ChecksumResult, say? I normally do this with


    my $httpArray = $xmlRef->{DepositoryProcessingRecord}{HttpHeaderMd}->{'HttpMeta'};
    for my $q (@$httpArray) {
                if ($q->{Name} eq "HTTP_OriginallyRequestedURL") { $hTTP_OriginallyRequestedURL = $q->{content} }
    }
but I can't seem to get the analogy to data that doesn't have a nice identifiable Name:content delineation. This doesn't work:
my $FILEARRAY = $xmlRef->{DepositoryProcessingRecord}{MultiFileDoc}->{OneUploadedFile};
  • Comment on Problem handling complex data structure with XML::Simple

Replies are listed 'Best First'.
Re: Problem handling complex data structure with XML::Simple
by runrig (Abbot) on Aug 10, 2011 at 21:46 UTC
    '{...}' indicates a hash reference. '[...]' indicates an array reference. So from your first structure, you would use:
    $VAR1->{OneUploadedFile}->[0]->[ChecksumResult};
    You can leave out all but the first '->' if you like. Also, maybe References quick reference would help.
Re: Problem handling complex data structure with XML::Simple
by ikegami (Patriarch) on Aug 10, 2011 at 21:47 UTC
    $VAR1->{OneUploadedFile}[0]{ChecksumResult}

    Although you'd normally have a loop to loop over the OneUploadedFile array.

      Sorry, sorry, I am just not getting it. Sigh. Anyway, I (of course) neglected to fully describe the XML hierarchy. It is not simply OneUploadedFile:ChecksumResult It is DepositoryProcessingRecord:MultiFileDoc:OneUploadedFile:ChecksumResult So, in trying to extrapolate, I am getting Not an ARRAY reference at ./parseXML.pl line 46. Line 46 is: my $checkSumResult = $xmlRef->{DepositoryProcessingRecord}->{MultiFileDoc}->{OneUploadedFile}->[0]->{'FinalDocStoragePath'}; I apologize; I just can't get my head around this.

        I'm basing it on the var you dumped. If you dumped $x, replace $VAR1 with $x. If you dumped $xmlRef->{DepositoryProcessingRecord}->{MultiFileDoc}, replace $VAR1 with $xmlRef->{DepositoryProcessingRecord}->{MultiFileDoc}.

        If you did dump $xmlRef->{DepositoryProcessingRecord}->{MultiFileDoc} and you are now getting this error, then $xmlRef->{DepositoryProcessingRecord}->{MultiFileDoc} no longer contains what you showed us it contained, and you'll have to adjust the code according to what it contains now.

Re: Problem handling complex data structure with XML::Simple
by Gulliver (Monk) on Aug 11, 2011 at 02:12 UTC