Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: XML understanding

by izut (Chaplain)
on Aug 22, 2006 at 11:35 UTC ( #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
Node Status?
node history
Node Type: note [id://568810]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2021-02-27 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?