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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |