in reply to Re: Reading XML LibXML
in thread Reading XML LibXML

Hmmm, so why not let XML::Simple take the strain ?

Because that isn't the question; it can't handle it :)

The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces. In particular, XML::LibXML is highly recommended.

The major problems with this module are the large number of options and the arbitrary ways in which these options interact - often with unexpected results.

Replies are listed 'Best First'.
Re^3: Reading XML LibXML
by hdb (Monsignor) on Oct 02, 2013 at 11:01 UTC
    use strict; use warnings; use XML::Simple; my $xml = <<XML; <table> <Entry No="1"> <lastname_>Dasd</lastname_> <firstname_>Dasd</firstname_> <street_>Dasd</street_> <houseno_>12</houseno_> <zip_>1231</zip_> <city_>Dasd</city_> <sex_>maennlich</sex_> <marital_>geschieden</marital_> <character_>Brille Sommersprossen</character_> <description_>asdas </description_> </Entry> <Entry No="2"> <lastname_>Dasd</lastname_> <firstname_>Dasd</firstname_> <street_>Dasd</street_> <houseno_>12</houseno_> <zip_>1231</zip_> <city_>Dasds</city_> <sex_>maennlich</sex_> <marital_>geschieden</marital_> <character_>Brille Sommersprossen</character_> <description_>asdas </description_> </Entry> </table> XML my $data = XMLin( $xml ); my @info = @{$data->{'Entry'}}; for my $entry (@info){ print "$entry->{lastname_}, $entry->{firstname_}\n"; }

      ...which dies horribly when there is only one <Entry>-element, e.g. the following XML:

      <table> <Entry No="1"> <lastname_>Dasd</lastname_> <firstname_>Dasd</firstname_> <street_>Dasd</street_> <houseno_>12</houseno_> <zip_>1231</zip_> <city_>Dasd</city_> <sex_>maennlich</sex_> <marital_>geschieden</marital_> <character_>Brille Sommersprossen</character_> <description_>asdas </description_> </Entry> </table>

      Which prooves what Anonymous monk said before... ;)

      McA

        True, but why would you write a script for a single record? ;)

      but that xml is the same as the original, there is no strain applied :/