ngbabu has asked for the wisdom of the Perl Monks concerning the following question:
<reference> ... ... <title type="journal">Harv L R</title> .... .... </reference>
My INI file info is like below:
Harv L R<TAB>Harvard Law Review MLR<TAB>Modern Law Review
The required output is as follow:
<reference> ... ... <title type="journal">Harvard Law Review</title> .... .... </reference>
The <title> is present in other locations also. We have to modify only titles which are child to <reference> and type="journal".
My code is like below:
use XML::XPath; use XML::XPath::XMLParser; $xp = XML::XPath->new(filename => 'mlr_648.xml'); $nodeset = $xp->find('//reference/title[@type="journal"]'); foreach my $node ($nodeset->get_nodelist) { $line=XML::XPath::XMLParser::as_string($node); if($line =~m!<title type="journal">(.*)</title>!) { $jb = $1; } &rep($jb); } sub rep { $jabb = $jb; open(DAT, "mlr.dat"); $/=undef; $x=<DAT>; while($x=~m!(.*)\t(.*)!ig) { %data = ("$1" => "$2"); $jname = $data{$jabb}; if($jname ne "") { print "<title type=\"journal\">$jname</title>\n"; } } }
I am getting required output. but I am unable to print entire XML with the modification in a separate file. Please help in two cases.
1. Print an error message if the corresponding full name is not found in the ini file
2. Print entire XML to a separate file.
Regards, Ganesh
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Modifying a Sepcifig node
by ikegami (Patriarch) on Oct 01, 2008 at 05:20 UTC | |
by ngbabu (Novice) on Oct 15, 2008 at 12:44 UTC | |
by Anonymous Monk on Oct 15, 2008 at 12:51 UTC |