If the code below doesn't answer your question (I can't really tell what the question is without some executable code that shows the problem), adjust it to show your problem and repost.

use strict; use warnings; use XML::LibXML; my $xml1 = <<XML; <doc> <id> <elements> <element1>matching text</element1> <element2>other text</element2> <element3>other text</element3> </elements> </id> </doc> XML my $xml2 = <<XML; <doc> <id> <elements> <element1>matching text</element1> <element2>another text</element2> <element3>other text</element3> </elements> </id> </doc> XML my $parser = XML::LibXML->new(); my $doc1 = $parser->parse_string($xml1); my $doc2 = $parser->parse_string($xml2); my @doc1Nodes = map {[$_->textContent(), $_->nodeName()]} grep {$_->nodeName() =~ /^element/} map {$_->childNodes()} $doc1->findnodes('//doc/id/elements'); my @doc2Nodes = map {[$_->textContent(), $_->nodeName()]} grep {$_->nodeName() =~ /^element/} map {$_->childNodes()} $doc2->findnodes('//doc/id/elements'); for my $index (0 .. $#doc1Nodes) { print "Mismatch in $doc1Nodes[$index][1]\n" if $doc1Nodes[$index][0] ne $doc2Nodes[$index][0]; }

Prints:

Mismatch in element2
True laziness is hard work

In reply to Re: print specific XML node number by GrandFather
in thread 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.