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

In reply to how to change node value based on other node value by ccherri

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.