in reply to Updating XML files

Hash the entries in file1 by their English term. Then iterate over the entries in file2, insert or update each entry based on its existence in the hash.

You haven't provided the full XML, so I had to wrap each file into <root>...</root> in order to be able to play with them. I named the first file 1.xml and the second one 2.xml . I then implemented the logic in XML::XSH2:

my $file2 := open 2.xml ; open 1.xml ; my $t := hash langSet[@xml:lang='EN']/tig/term /root/termEntry ; for my $entry in $file2/root/termEntry { my $entry1 = xsh:lookup('t', $entry/langSet[@xml:lang='EN']/tig/te +rm) ; if ($entry1) { for my $lang in $entry/langSet/@xml:lang { if (0 = count($entry1/langSet[@xml:lang=$lang])) cp $lang/.. into $entry1 ; } } else { cp $entry into /root ; } } save :b ;

BTW, I had to remove the </termEntry> before <langSet xml:lang="FR"> in the expected output, I hope that's what you meant.

($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,

Replies are listed 'Best First'.
Re^2: Updating XML files
by Anonymous Monk on May 24, 2016 at 13:59 UTC

    Hi

    Thank you very much for your help. However, I am not able to run your code because of an error I get.

    Use of := for an empty attribute list is not allowed

    Can you please advise?

    Thanks

      You can't run it as Perl code. Install XML::XSH2, save the code as script.xsh , run it with xsh script.xsh . Or, supply the whole code to the xsh function inside of a Perl script.
      ($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,