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

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"; }

Replies are listed 'Best First'.
Re^4: Reading XML LibXML
by McA (Priest) on Oct 02, 2013 at 11:07 UTC

    ...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? ;)

        Probably a script fetching external xml-files, where you get 0-n <Entry>-tags in each file... ;)

Re^4: Reading XML LibXML
by Anonymous Monk on Oct 02, 2013 at 11:08 UTC
    but that xml is the same as the original, there is no strain applied :/