onegative has asked for the wisdom of the Perl Monks concerning the following question:
<HOSTNAME name='apple'> <PATROL> <ACL> <USERNAME name='ml3007'> <HOST>*</HOST> <PERMISSION>COPS</PERMISSION> </USERNAME> </ACL> </PATROL> </HOSTNAME>
use strict; use warnings; use XML::LibXML; my $filename = $ARGV[0]; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($filename); my $xc = XML::LibXML::XPathContext->new( $doc->documentElement() ); foreach my $sections ($xc->findnodes('/HOSTNAME/PATROL/ACL/USERNAME' +)) { my($username) = $sections->getAttribute('name'); my($permissions) = $sections->findnodes('./PERMISSION'); my($host) = $sections->findnodes('./HOST'); print $username->to_literal, "\n"; print $permissions->to_literal, "\n"; print $host->to_literal, "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do you get attribute values using XML::LibXML
by PeterPeiGuo (Hermit) on Dec 15, 2010 at 01:11 UTC | |
|
Re: How do you get attribute values using XML::LibXML
by tofanikanudo (Initiate) on Dec 15, 2010 at 13:57 UTC | |
|
Re: How do you get attribute values using XML::LibXML
by grantm (Parson) on Dec 16, 2010 at 20:30 UTC | |
|
Re: How do you get attribute values using XML::LibXML
by ikegami (Patriarch) on Dec 16, 2010 at 21:00 UTC |