in reply to confirming key in xml?

Hi ccherri,

You can use XML::Simple to do modifications too:

use XML::Simple; my $inst_set = XMLin( 'test.xml', KeepRoot => 1 ); foreach my $Channel (@{$inst_set->{Settings}->{Channels}->{Channel}}) +{ if ( $Channel->{Voltage} ) { print "Old voltage: $Channel->{Voltage} -- "; $Channel->{Voltage} *= 2.0; print "New voltage: $Channel->{Voltage}\n"; } } my $xml = XMLout( $inst_set, KeepRoot => 1 ); print $xml;
Update:'KeepRoot' was added in according to AM's comments below.

Replies are listed 'Best First'.
Re^2: confirming key in xml?
by Anonymous Monk on Apr 06, 2015 at 21:59 UTC

    XML::Simple is incredibly brittle when it comes to writing and especially round-tripping XML. For a perfect example of this read this thread. Sorry, but I have to strongly recommend against XML::Simple in this case. Recommendations for other XML modules given e.g. here.

Re^2: confirming key in xml?
by Anonymous Monk on Apr 06, 2015 at 22:20 UTC

    ... In fact, this code is actually a good example of some of the issues one has to deal with when using XML::Simple to write XML... did you notice that it changed the name of the root node from Settings to opt? Sure, there are options to fix that, but the previously linked thread is a wonderful example of the corners one can paint oneself into.

      Thanks for pointing out the missing 'KeepRoot'.
Re^2: confirming key in xml?
by karlgoethebier (Abbot) on Apr 07, 2015 at 18:28 UTC
    "You can use XML::Simple..."

    Some quirks with XML::Simple have been mentioned by some illuminated bros - but there is XML::LibXML::Simple

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»