zak_s has asked for the wisdom of the Perl Monks concerning the following question:
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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: print specific XML node number
by GrandFather (Saint) on Dec 04, 2013 at 22:42 UTC | |
|
Re: print specific XML node number
by GotToBTru (Prior) on Dec 04, 2013 at 23:14 UTC | |
by zak_s (Initiate) on Dec 05, 2013 at 19:35 UTC | |
by zak_s (Initiate) on Dec 11, 2013 at 17:51 UTC |