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.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: get common node of xml in comma separated string by thanos1983
in thread get common node of xml in comma separated string by snehit.ar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.