Possible Duplicate:
Why am I getting an “Out of memory” error with Perl's XML::Simple?
I have a XML file like this:
<message>
<c1>
<rrcConnectionSetupComplete>
<rrc-TransactionIdentifier>2</rrc-TransactionIdentifier>
<criticalExtensions>
<c1>
<rrcConnectionSetupComplete-r8>
<selectedPLMN-Identity> 1 </selectedPLMN-Identity>
<dedicatedInfoNAS> 07410109014290112345671000028020000f0 </dedicatedInfoNAS>
</rrcConnectionSetupComplete-r8>
</c1>
</criticalExtensions>
</rrcConnectionSetupComplete>
</c1>
</message>
I am using Perl code like this to access the data in XML file (I should stick on to this format of accessing)
#!/usr/bin/perl
use strict;
use XML::Simple;
my $xml = new XML::Simple;
my $data = $xml->XMLin("uL-DCCH-Message.xml");
my $rrc_trans_identifier = $data->{'c1'}->{'rrcConnectionSetupComplete'}->{'rrc-TransactionIdentifier'};
print "rrc_trans_id :: $rrc_trans_identifier\n";
my $selected_plmn_id = $data->{c1}->{rrcConnectionSetupComplete}->{criticalExtensions}->{c1}->{'rrcConnectionSetupComplete-r8'}->{'selectedPLMN-Identity'};
print "plmn identity :: $selected_plmn_id\n";
my $rrc_dedicated_info_nas = $data->{c1}->{rrcConnectionSetupComplete}->{criticalExtensions}->{c1}->{'rrcConnectionSetupComplete-r8'}->{dedicatedInfoNAS};
print "dedicated info nas :: $rrc_dedicated_info_nas\n";
The output produced is,
rrc_trans_id :: 2
plmn identity :: 1
dedicated info nas :: 07410109014290112345671000028020000f0
Perl code using XML::Simple is working fine for smaller XML files (as shown in the above output).
But If XML file is large, then XML::Simple cannot handle and it is showing the error message Ran out of memory.
Are there any other XML Parsers I can use so that I can access the elements in XML file in the similar manner as shown above?
If there is any other parsers available, can any one give an example by following the same conventions I am following for XML::Simple.
There are two types of XML Parsers available:
simple ones that read the whole XML
file into memory and generate an easy
accessible data structure, this takes
a rather big amount of memory so
you’ll get into trouble with bigger
files. Their advantage is that they
are usually very easy to work with.
the SAX based parsers which process
the XML element by element. To work
with this parsers the developer
(you!) has to register callbacks for
every interesting element and work
with the information from the
callbacks. Everytime the SAX parser
encounters a given element the
associated callback is executed and
you are able to only work with the
interesting tags rather the whole
file at once. This parsers keep the
memory usage (potentially) very low
but require substatially more work.