> the XML will be loaded from STDIN. I am sorry, but I don't have strong perl skills :(

Perl skills are irrelevant here. You just need to read the documentation.

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,

In reply to Re^3: Update nodes in XML document by choroba
in thread Update nodes in XML document by corfuitl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.