in reply to How to get the node value of each node?
I prefer XML::LibXML for XML processing:
which produces:#!/usr/bin/perl use strict; use warnings; use XML::LibXML; my $file = shift || die "usage $0 xmlfile"; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file( $file ); my $root = $doc->getDocumentElement; my @modules = $root->findnodes( '/Product/Module' ); foreach my $module ( @modules ) { my $name = $module->findvalue( '@name' ); print "Module Name: $name\n"; my @dirs = $module->findnodes( 'SourceDir/@name' ); foreach my $dir ( @dirs ) { print "\t", $dir->value, "\n"; } print "\n"; }
Module Name: nw /testnw/nwtool Module Name: hw /prod/hw /test/hw
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to get the node value of each node?
by kkavitha (Initiate) on Aug 17, 2009 at 13:42 UTC |