Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Pasring XML into a simple hash

by Kanji (Parson)
on Jun 21, 2001 at 09:38 UTC ( #90291=note: print w/replies, xml ) Need Help??


in reply to Pasring XML into a simple hash

I have a "XML like" file <...>

If you don't want to write a custom parser from scratch or within the framework something like Parse::RecDescent provides, you'll need to convert your file into valid XML before you could use XML::Parser or XML::Simple.

But if you do, doing what you need is a cinch ...

use XML::Simple; my $xml = XMLin(<<__XML__); <posts> <post> <jobnumber>1234</jobnumber> <location>Somecity, NJ</location> </post> <post> <jobnumber>87922</jobnumber> <location>Othercity, AK</location> </post> </posts> __XML__ foreach my $post ( @{ $xml->{'post'} } ) { print "City: $post->{'location'}\n"; }

    --k.


Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-05-27 21:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (162 votes). Check out past polls.

    Notices?