in reply to Re: XML Parsing Out of Memory error
in thread XML Parsing Out of Memory error

Sorry about the confusion, this is a snippet from a larger xml structure, I should have included more XML for the example. Try the following code instead:
#!/usr/bin/perl use XML::Simple; use Data::Dumper; my $xml = qq|<?xml version="1.0" standalone="no"?> <!DOCTYPE document SYSTEM "whocares.dtd"> <document> <QuestionList> <Question> <Id>3</Id> <Text>Are dingos your friend?</Text> <Answer>Satisfactory</Answer> </Question> <Question> <Id>3</Id> <Text>Should I have hit preview a second time?</Text> <Answer>Yes</Answer> </Question> </QuestionList> <QuestionList> <Question> <Id>11</Id> <Text>Should this run out of memory?</Text> <Answer>No</Answer> </Question> </QuestionList> </document>|; my $xml_ref = XMLin($xml); print Dumper $xml_ref; print $xml_ref->{'QuestionList'}->{'Question'}->[0]->{'Answer'};
in the full code I check to see if this is a list of questions or not... But if you try that one out Question indeed is an array ref as my print would suggest.

Replies are listed 'Best First'.
Re: Re: Re: XML Parsing Out of Memory error
by mirod (Canon) on Feb 28, 2002 at 17:37 UTC

    Then you are looking for:

    $xml_ref->{'QuestionList'}->[0]->{Question}->[0]->{Answer}

    I have found using the debugger pretty useful in such a case: once the XML had been XMLin'd, I x'd $xml_ref->{'QuestionList'}, saw it was an array, then x'd $xml_ref->{'QuestionList'}->[0], then $xml_ref->{'QuestionList'}->[0]->{Question} and figured out it was also an array... hence the final code. I often use this technique to debug complex data structures.