Dear All,
I am new to the PERL using XML::Twig, we need to navigate each reference element which is parent and compare both the <title> and <original_text> elements. While doing so in my xml there are multiple <title> tags present in the reference element. Thus our code produce wrong output for comparing each <title> text with <original_text> text.
I have tried the below code:
Perl-Twig.pl
Code:
use strict;
use XML::Twig;
my @arrTitle;
my @arrOriginalText;
my $t= XML::Twig->new( twig_roots => { 'title' => \&title_ext, 'original_text' => \&org_ext }
);
$t->parsefile( 'Test.xml');
sub title_ext
{ my( $t, $elt)= @_;
push(@arrTitle, $elt->text);
$t->purge; # frees the memory
}
sub org_ext
{ my( $t, $elt)= @_;
push(@arrOriginalText, $elt->text);
$t->purge; # frees the memory
}
Our Input: Test.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<references>
<reference id="[1]">
<book book_type="monograph">
<book_metadata>
<contributors>
<person_name sequence="first" contributor_role="author">
<given_name>L. I.</given_name>
<surname>Rozonoer</surname>
<suffix></suffix>
</person_name>
<organization sequence="first|additional" contributor_role="author|editor|chair|translator"></organization>
</contributors>
<titles>
<title>Thermodynamics and Regulation of Biological Processes</title>
</titles>
<series_metadata>
<titles>
<title></title>
</titles>
<isbn></isbn>
<doi_data>
<doi></doi>
<resource></resource>
</doi_data>
<comments>
<comment></comment>
</comments>
</series_metadata>
</book_metadata>
<original_text>[11] L. I. Rozonoer, <i>Thermodynamics and Regulation of Biological Processes</i>, de Gryter, Berlin, 1984.</original_text>
</book>
</reference>
<reference id="[2]">
<journal>
<journal_metadata>
<full_title></full_title>
<abbrev_title>Energie, Wirtschaftswachstum und technischer Fortschritt Phys. Bl.</abbrev_title>
<issn></issn>
<coden></coden>
</journal_metadata>
<journal_article>
<titles>
<title></title>
</titles>
</journal_article>
<original_text>[1] R. Kümmel, D. Lindenberger, W. Eichborn, Energie, Wirtschaftswachstum und technischer Fortschritt, Phys. Bl., <b>53</b>, 869 (1997).</original_text>
</journal>
</reference>
</references>
Is there any way to pass the argument as XPath like 'book/titles/title' and also for the instances 'Journal/titles/title'.
Kindly advise/help us on this.
Thanks,