Hello Monks
I'm fairly new to Perl working with multiple XML files and trying to approach the following.
Im comparing text contents of different elements from different XML files
now what I need is to print the node im currently at where I found a match. What im doing is this:

my $parser = XML::LibXML->new(); my $doc = $parser->parse_file("main_file.XML"); my $doc1 = $parser->parse_file("second_file.XML"); my @nodes_from_main= $doc0->findnodes('//path/to/element/text()'); my @nodes_from_second = $doc1->findnodes('//path/to/element/text()');

this is how i get the text to match with other files
now I need to do this:

for my $node_main (@nodes_from_main) { for my $node_second (@nodes_from_second) if (text from main equal text from second, "which I did already") { <p> print my matching node from the second file;<br> How to do this part</p> } esle { do nothing; } }

i want something like print @node_match_from_second [$i]
where $i is my current text matching iteration. I tried but my counter seem not to work properly for some reason...any suggestions?
I will be adding another "findnodes" to find what I need to print
so I only need to pick the node that its index is matching my current text matching index. maybe looping through 2 files at the same time ? but I was thinking maybe a counter
and then a direct print through specifying the index as I have indicated above

<doc> <id> <elements> <element1>matching text</element1> <element2>other text</element2> <element3>other text</element3> </elements> </id> </doc> <p>I need to print everything within elements </p>

In reply to print specific XML node number by zak_s

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.