Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Converting XML to array of array.

by choroba (Archbishop)
on Jan 23, 2017 at 10:51 UTC ( #1180146=note: print w/replies, xml ) Need Help??


in reply to Converting XML to array of array.

Use Data::Dumper to visualise the structure you want to iterate over. You need to supply the root element name at the top: book . The following should give you a clue:

for my $id (keys %{ $xml->{book} }) { for my $s (keys %{ $xml->{book}{$id} }) { print "$s: @{ $xml->{book}{$id}{$s} }\n"; } }

Also, don't use XML::Simple.

Here's how to process the XML in XML::XSH2:

open file.xml ; for //book echo (title) edition (edition) by (authors/author/firstname | authors/author/lastname) '(' isbn (isbn) ')' ;

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Converting XML to array of array.
by GotToBTru (Prior) on Jan 23, 2017 at 14:00 UTC

    Homework exercise probably specifies using XML::Simple or XML::Parser. It may prove useful to know about better alternatives, just not at the moment.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2020-10-23 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (234 votes). Check out past polls.

    Notices?