Script to replace a value in XML

November 13, 2009 at 07:22:22
Specs: Windows XP
HI, I have about 400 xml files that have error in the productID line:
<Product productID="0001">
the 0001 needs to be replace with another value which is found in: <researchID="KR-AAPL-2007-01-10" language="eng">

Can someone help me write a script that will go through the 400 files and take the researchID and place it instead of 0001 in productID? Thanks in advance!!!

See More: Script to replace a value in XML

Report •

November 13, 2009 at 15:03:22
should not be hard, but you forgot to explicate the problem more specifically.
<researchID="KR-AAPL-2007-01-10" language="eng">

does this string occur in the same file as the "product id"?
if not the same file, is the string in one file or multiple files?
does it occur only once?
what portion of the researchID do you want to put into productID? all the quoted part "KR..." or just part of it?
these might be dumb questions, i don't know, but since no one else has responded i will risk looking foolish.
here's something to try and start out with:
(ffile source of fix-data, idfile is file to fix; newfile is output)
setlocal enabledelayed expansion
for /f "tokens=1 delims= " %%a in ('find "<researchID=" ffile') do (
set id=%%a)
set id=!id:~12,20!
set /a ct=0
for /f "tokens=* delims=" %%a in (idfile) do (
set line=%%a
set /a ct+=1
if ct equ 1 (
set line=!line:~0,19!!id!>)
echo !line! >> newfile)
move /y newfile idfile

code not tested, make backup of idfile or disable last line!

Report •

November 13, 2009 at 18:18:20
@OP, show your xml file. A picture speaks a thousand words!!

GNU win32 packages | Gawk

Report •

Related Solutions

Ask Question