Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Reading XML LibXML

by Bloodnok (Vicar)
on Oct 02, 2013 at 10:15 UTC ( [id://1056594]=note: print w/replies, xml ) Need Help??


in reply to Reading XML LibXML

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

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Reading XML LibXML
by Anonymous Monk on Oct 02, 2013 at 10:56 UTC

    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.

      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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1056594]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found