I have XML which may contain an unknown number of <A> and <B> elements:
<?xml version="1.0" encoding="UTF-8" ?>
<Messages>
<A>
<Message>
<Field1>
<Field2>
<Field3>
</Message>
</A>
<B>
<Message>
<Field1>
<Field2>
<Field3>
</Message>
</B>
<B>
<Message>
<Field1>
<Field2>
<Field3>
</Message>
</B>
<B>
<Message>
<Field1>
<Field2>
<Field3>
</Message>
</B>
</Messages>
I read in the data like this:
my $data = XMLin($content);
I can parse all the <B> elements like this:
foreach $b_msg (@{$data->{B}->{Message}})
but the same does not work for <A> elements:
foreach $b_msg (@{$data->{A}->{Message}})
I don't understand why I can loop through all the <B> elements but the foreach for the <A> elements is never entered.
Please explain. Thanks.
Our community of experts have been thoroughly vetted for their expertise and industry experience.