Looking to make a change to an xml tag from a list of info found in a txt file.

txt file contains a list of data as follows

644111111111,102.23

644255555555,94.8

644492835633,17.71

XML contains two tags where this info can be found:

<KEY_BOL_REF>644111111111</KEY_BOL_REF>

<CARBOL_TRSP_VALUE>0.00</CARBOL_TRSP_VALUE>

I need to find the corresponding 12 digit number from the txt in the xml and replace its CARBOL tag with the amount found next to the number in the text (after the comma). I am able to find the number but can't seem to change the amount of CARBOL. Here is the code i have so far. it also ensures that another tag is set to USD. Thanks.

open(BASE, "C:/POS/POSA.xml"); open(IN, "C:/POS/Macro/awb.txt"); open(OUT, ">POSA_new.xml"); %map = (); while (<IN>) { chomp $_; @items = split(/\,/, $_); $map{$items[0]} = $items[2]; } close IN; $cur_awb = "0"; $cur_val = $map{$items[0]} = $items[2]; while (<BASE>) { chomp $_; if ($_ =~ m/\<KEY_BOL_REF\>(\d*)\<\/KEY_BOL_REF\>/) { $cur_awb = $1; print OUT $_ . "\n"; } elsif ($_ =~ m/\<CARBOL_TRSP_VALUE\>/) { print OUT "\t<CARBOL_TRSP_VALUE>" .$cur_val. "</CARBOL_TRSP_VA +LUE>\n"; } elsif ($_ =~ m/\<CARBOL_TRSP_CUR\/\>/) { print OUT "\t<CARBOL_TRSP_CUR>USD</CARBOL_TRSP_CUR>\n"; } else { print OUT $_ . "\n"; } }

In reply to find text in xml tag and replace another tag from data in same txt file by alexlabelle

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.