Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: XML parsing

by devnul (Monk)
on May 09, 2005 at 22:54 UTC ( #455360=note: print w/ replies, xml ) Need Help??


in reply to XML parsing

I'm having a really hard time reading your example (please use code tags?).. Understanding your result is difficult too. I'll make some "guesses" at what you might be trying to do and hope this helps...

I really do not know what you meant to do with the XML document you posted from your comments, so I am left to guess at what you meant to do. Here is my version:

<hosts> <host name="jimmy"> <function>web</function> <function>dns</function> <location>miami</location> </host> <host name="haffa"> <function>nfs</function> <function>quake</function> <location>hell</location> </host> </hosts>

Now here's the code to parse it: (I did not know what you meant to do with the hash you passed into XMLin, so I removed it)

use XML::Simple; use Data::Dumper; # create object my $xml = new XML::Simple (); # read XML file my $data = $xml->XMLin("/tmp/hosts.xml"); print Dumper($data);


And here is the output:
$VAR1 = { 'host' => { 'haffa' => { 'function' => [ 'nfs', 'quake' ], 'location' => 'hell' }, 'jimmy' => { 'function' => [ 'web', 'dns' ], 'location' => 'miami' } } };

I think the results are fairly self-explanatory?

- dEvNuL


Comment on Re: XML parsing
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (22)
As of 2014-10-30 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls