my $dom = 'XML::LibXML'->load_xml(IO => *STDIN);
> update only the alt-title with origin="tilte"
Again, not a Perl skills question. findnodes uses XPath Expressions, so just modify it:
my ($other_title) = $dom->findnodes('//file/body/group/unit/alt-title/
+otherTitle[@origin="tilte"]');
Is it "tilte" or "title"?
> the new values will be taken from another file which will contain the same number of lines as the nodes.
Do you know how to read lines from a file? See open and the diamond operator in perlop. For example, I created an input file called 1 with the following contents:
a
b
c
Then, I created a simple XML file called 1.xml:
<root>
<one>
<two origin="a"/>
<two origin="b"/>
</one>
<one>
<two origin="b"/>
<two origin="a"/>
</one>
<one>
<two origin="a">old</two>
<two origin="b">old</two>
</one>
</root>
Finally, here's the script that replaces the text in two with origin="a" by the values read from the given file. $. is a special variable that contains the input's line number, you can use it to index the nodes in the XPath Expression:
#!/usr/bin/perl
use warnings;
use strict;
use XML::LibXML;
my $new_values_file = shift;
my $dom = 'XML::LibXML'->load_xml(IO => *STDIN);
open my $in, '<', $new_values_file or die "$new_values_file: $!";
while (<$in>) {
chomp;
my ($two) = $dom->findnodes("/root/one[$.]/two[\@origin='a']");
$two->removeChildNodes if $two->findnodes('text()');
$two->appendText($_);
}
print $dom;
Run as
perl script.pl 1 < 1.xml
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|