Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: XML understanding

by izut (Chaplain)
on Aug 22, 2006 at 11:35 UTC ( [id://568810]=note: print w/replies, xml ) Need Help??


in reply to XML understanding

You can use XML::Twig for parsing that XML tree:

#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $twig = XML::Twig->new( twig_handlers => { 'server' => sub { print "server: ", $_->first_child('name')->tex +t, "\n"; foreach my $c ($_->children('file')) { print "filename: ", $_->text, "\n" for +each $c->children('filename'); } }, }, ); $twig->parse(*DATA); __DATA__ <config> <server> <name>server1</name> <file> <filename>/etc/named.conf</filename> <filename>/etc/nsswitch.conf</filename> </file> </server> <server> <name>server2</name> <file> <filename>/etc/named.conf</filename> <filename>/etc/nsswitch.conf</filename> <filename>/etc/hosts</filename> </file> </server> </config>

Outputs:

server: server1 filename: /etc/named.conf filename: /etc/nsswitch.conf server: server2 filename: /etc/named.conf filename: /etc/nsswitch.conf filename: /etc/hosts

Igor 'izut' Sutton
your code, your rules.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 16:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found