snehit.ar has asked for the wisdom of the Perl Monks concerning the following question:
Output required as : Jhon,Ram,Rahim code I tired ...<application_list> <application id = "111"> <contacts> <technical> <name>John</name> <name>Ram</name> <name>Rahim</name> </technical> </contacts> </application> <application_list>
I tired above code but not getting comma separated values in o/p : JhonRamRahim#! /usr/bin/perl use warnings; use strict; use XML::XPath; my $appxml = 'ApplicationList.xml'; my $appxp = XML::XPath->new(filename => $appxml); my $xp = $appxp->findnodes('//application_list/application/'); my %appid; my @apprecords; foreach my $appnodeset ($xp->get_nodelist) { my $id = $appnodeset->find('@id')->string_value; $id =~ s/^\s+|\s+$//g; foreach my $spltname ($appxp->findnodes('./contacts/technical',$ap +pnodeset)) { my $name = join ",", map $_->string_value, $spltname->findno +des('.//name1'); # add this as suggested by choroba $appid{$id} = $name; print $name; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: get common node of xml in comma separated string
by choroba (Cardinal) on Aug 02, 2017 at 12:24 UTC | |
|
Re: get common node of xml in comma separated string
by 1nickt (Canon) on Aug 02, 2017 at 12:23 UTC | |
|
Re: get common node of xml in comma separated string
by thanos1983 (Parson) on Aug 02, 2017 at 15:00 UTC | |
by snehit.ar (Beadle) on Aug 02, 2017 at 15:59 UTC |