Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Pasring XML into a simple hash

by Kanji (Parson)
on Jun 21, 2001 at 09:38 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://90291]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-18 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found