#!/usr/bin/perl use warnings; use strict; use XML::XSH2; package XML::XSH2::Map; our ($path, $value, $v); package main; xsh << 'end.'; open 1.xml ; register-namespace am http://www.abc.com/xml/appmanagement ; end. my ($replace, $add); open my $PROP, '<', 'properties' or die $!; while (<$PROP>) { chomp; s=^M_([RA])_/?== or next; my $action = $1; ($path, $value) = split / = /; xsh << ' end.'; $v = //am:name[.=$path]/../am:value ; if $v set $v/text() $value ; end. next if $v; $path =~ s=/=/am:=g; xsh "set /am:$path '$value'"; } xsh 'save :f new.xml';
This was the created file:
I am not sure that is what you exactly need, though. Especially in case of the last two lines of the properties file: the XPath matches 3 different nodes, it is not clear which one you want to modify.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to replace the existing values and to add the new nodes which are not existed based on test file
by perladdict (Chaplain) on Apr 02, 2014 at 11:41 UTC |