An interesting thread appeared on the SOAP::Lite newsgroup about how to parse arrays of arrays. As you might expect, there are a number of ways to do this in perl, but I wanted to post a specific solution that was discovered by the original poster of the message...
How to parse an array of arrays:
my $som = SOAP::Deserializer->deserialize($xml);
my $i = 0;
foreach my $a ($som->dataof("//person/*")) {
$i++;
my $j = 0;
foreach my $b ($som->dataof("//person/[$i]/*")) {
$j++;
...
}
}
The above method proved to be one of the faster methods of achieving this, but as Randy Ray points out: the XML parser you use plays an important role in performance as well. Just look at his benchmark results comparing two different traversal strategies for embedded arrays:
XML::LibXML: 1 wallclock secs ( 1.10 usr + 0.00 sys = 1.10 CPU) @ 909.09/s (n=1000) Improved: 11 wallclock secs (10.71 usr + 0.00 sys = 10.71 CPU) @ 93.37/s (n=1000) XML::XPath: 16 wallclock secs (15.92 usr + 0.00 sys = 15.92 CPU) @ 62.81/s (n=1000) Original: 20 wallclock secs (19.89 usr + 0.00 sys = 19.89 CPU) @ 50.28/s (n=1000)
Ok, so perhaps I want to use a different XML Parser than what 'ships' with SOAP::Lite. How do you do that?
Thom Eden
Posted by: Thom Eden | May 06, 2004 at 12:52 PM