Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How to replace the existing values and to add the new nodes which are not existed based on the properties file

by choroba (Archbishop)
on Apr 01, 2014 at 21:25 UTC ( #1080640=note: print w/replies, xml ) Need Help??


in reply to How to replace the existing values and to add the new nodes which are not existed based on the properties file

I usually use XML::XSH2, a wrapper around XML::LibXML, to process XML files. I tried the following:
#!/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:

Removed per OP request (confidential data).

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.

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
  • Comment on Re: How to replace the existing values and to add the new nodes which are not existed based on the properties file
  • Download Code

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
    Hi Choroba, Thanks for your inputs, i tried to install the perl module in active Perl using PPM, but it is displaying no package found as below.

    C:\Perl\bin>ppm search XML::XSH2 *** no packages matching 'XML::XSH2' found ***
    I have already installed XML::LibXML,XML::DOM,XML::SAX moudles, but i unable to install XML::XSH2.Can you please suggest is XML::XSH2 supports on windows active perl?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1080640]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2020-03-28 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (167 votes). Check out past polls.

    Notices?