Have an xml file in which one parent tag has multiple child tags and each of these tags have some value. I need to get all child node values in an array, iterate through each and perform specific task on values. When I try to get records what I am ending up is with entire child node as a single element of an array. How do read each child as an seperate element of an array. What I am using is XML::LibXML

<?xml version="1.0" encoding="UTF-8"?> <cidconfig> <createnew> <logon>xxx,xxx</logon> <startnew>xxx,xxx</startnew> <choosecs>xxx,xxx</choosecs> <chooseapp>xxx,xxx</chooseapp> <chooseconfig>xxx,xxx</chooseconfig> <chooseconftype>xxx,xxx</chooseconftype> <startnew1>xxx,xxx</startnew1> <activate>xxx,xxx</activate> </createnew> </cidconfig> Code I have written use strict; use warnings; use diagnostics; use XML::LibXML; my $dom = XML::LibXML->load_xml(location => $ARGV[0]); my $root = $dom->getDocumentElement; my @records = $root->findnodes("//createnew"); print @records; foreach my $y (@records) { my $x = $y->childNodes; print "$x"; print "Yes\n"; } Output <createnew> <logon>xxx,xxx</logon> <startnew>xxx,xxx</startnew> <choosecs>xxx,xxx</choosecs> <chooseapp>xxx,xxx</chooseapp> <chooseconfig>xxx,xxx</chooseconfig> <chooseconftype>xxx,xxx</chooseconftype> <startnew1>xxx,xxx</startnew1> <activate>xxx,xxx</activate> </createnew> xxx,xxx xxx,xxx xxx,xxx xxx,xxx xxx,xxx xxx,xxx xxx,xxx xxx,xxx Yes

In reply to Get all child node values for a particular parent in xml into an array by rahulruns

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.