You are 100% right about your assumption "If the contents of <element1> match in the 2 documents, you want to print the enclosing <elements>...</elements>. Of both documents? Or just one?" .... Im trying to print both
let me be more specific I have previously done this, Which is printing nodes im interested in regardless of match or miss match.
Now Im interested in both match and the whole node that has this specific <element1> text match. Please read my comments to get a feeling of what im trying to do

my $parser = XML::LibXML->new(); my $doc = $parser->parse_file("main_file.XML"); my $doc1 = $parser->parse_file("second_file.XML"); #get my text my @nodes_from_main= $doc0->findnodes('//path/to/element/text()'); my @nodes_from_second = $doc1->findnodes('//path/to/element/text()'); #get the node containing the previous text i.e containing <element1> my @node_I_need_from_main= $doc0->findnodes('//path/to/<elements>'); my @node_I_need_from_second = $doc1->findnodes('//path/to/<elements>)' +); #Note that main is unique meaning it will have only one instant from t +he text im matching #where my second, third, fourth....etc. will or might have more than o +ne match #now im trying to find the match which is working fine my $i=0; for my $node_main (@nodes_from_main) { #print my node from the main file, next look for matches #the problem is im looping through nodes at //path/to/element/text( +) #dont know how to loop through '//path/to/<elements>' at the same t +ime #or change my path at this particular instant for my $node_second (@nodes_from_second) { if (text from main equal text from second, "which I did already") { print my matching node from the second file, same issue I discu +ssed in the above comment. Im looking for something like this: print $node_I_need_from_second [$i] (matching node) or any other way to get the same result i.e print node: <elements> <element1>matching text</element1> <element2>other text</element2> <element3>other text</element3> </elements> } esle { #do nothing; } ++$i; } }

I hope this gives a much more clear idea about my problem...An alternative would be an Xpath expression something like "find all nodes where <element1> = $value"
this will actually this gives me a 2 in one solution


In reply to Re^2: print specific XML node number by zak_s
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.