ccherri has asked for the wisdom of the Perl Monks concerning the following question:
I need to change the value of one node/key if another node/key has a particular value. For instance if the Name node = L1 in a channel element, change the value of the voltage node in that same channel element. I have to set the voltage in each channel according to the name value. I don't really care what the original voltage value is and would prefer to ignore it.
<Settings> <Channels> <Channel Name="R1" Voltage="100" Test="1"/> <Channel Name="R2" Voltage="200" Test="0"/> ... <Channel Name="L1" Voltage="400" Test="0"/> <Channel Name="L360" Voltage="120" Test="1"/> </Channels> </Settings>
So I would expect the code to work something like this...
if($root->findnodes('/Settings/Channels/Channel/Name="L1"')){ #<-Chan +nel name = "L1" my ($L1value) = $root->findnodes('/Settings/Channels/Channel/Name="L1 +" @Voltage[.="400"]'); $L1value->setValue(300); }
but that doesnt work. I cant figure out how to change the voltage based on the value of Name.
Thanks Monks C
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to change node value based on other node value
by choroba (Cardinal) on Apr 08, 2015 at 00:58 UTC | |
by ccherri (Acolyte) on Apr 08, 2015 at 18:10 UTC | |
|
Re: how to change node value based on other node value
by Anonymous Monk on Apr 08, 2015 at 00:33 UTC | |
by ccherri (Acolyte) on Apr 08, 2015 at 17:30 UTC | |
by Anonymous Monk on Apr 08, 2015 at 22:50 UTC | |
|
Re: how to change node value based on other node value
by Marshall (Canon) on Apr 09, 2015 at 06:21 UTC | |
by Anonymous Monk on Apr 09, 2015 at 14:54 UTC |