in reply to get common node of xml in comma separated string
Hello snehit.ar,
I run your updated code and sample of data and I got:
$ perl test.pl no element found at line 12, column 0, byte 209: </application> <application_list> ^ at /home/tinyos/perl5/lib/perl5/x86_64-linux/XML/Parser.pm line 187.
Simply modify your xml file to:
<application_list> <application id = "111"> <contacts> <technical> <name>John</name> <name>Ram</name> <name>Rahim</name> </technical> </contacts> </application> </application_list>
And re run your script:
#!/usr/bin/perl use strict; use warnings; use XML::XPath; use feature 'say'; 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', $appnodeset) ) { my $name = join ",", map $_->string_value, $spltname->findnodes('.//name'); # add this as suggested by chorob +a $appid{$id} = $name; say $name; } } __END__ $ perl test.pl John,Ram,Rahim
Hope this helps, BR.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: get common node of xml in comma separated string
by snehit.ar (Beadle) on Aug 02, 2017 at 15:59 UTC |