G'day all. I have some code to random generate destination tags for a program I am creating. I am using CMD for this as I've already have 90% of the coding done. up to this point.
What I have is the program pulls 20 random tags and saves them as a variable. I have it set up in a loop and appends a text file every time it runs. Also I have a counter to tell me how many tags have been input into the saved text file.
Now, comes the tricky part. I need the program to update an .XML file that is already structured. All specific nodes of the xml must remain or else the main program that uses the .XML will not load the file properly. My Objective here is updating this node with the random generated 'tags' and input them in the said .XML file.
:Main
Set tags1=%Random%
If /i %tags1% GTR 6 goto Main
If /i %tags1% LSS 1 goto Main
goto Maniaa
:Maniaa
If %tags1% == 1 set tags2=NA
If %tags1% == 2 set tags2=FR
If %tags1% == 3 set tags2=LA
If %tags1% == 4 set tags2=BR
If %tags1% == 5 set tags2=SY
If %tags1% == 6 set tags2=BU
::This block of code is the random tag generation.
::This will echo out the saved tags
Echo ^<destinationTag^>%tags2%^</destinationTag^> >> tags2.txt
goto Main2
:Main2
::Setting up the counter within the tags2.txt
set file=tags2.txt
set /a cnt=0
for /f %%a in ('type %file%^|find "" /V /C') do set /a cnt=%%a
Echo %file% has %cnt% Random Generated Tags, Current %tags2%
::Once program reaches the required tags we can exit program
::THIS PART IS WHAT I AM TRYING TO DO.
for /f %%i in ('findstr "<destinationTag>%tags2%^</destinationTag^>"
tags2.txt') do echo ^<destinationTag^>%tags2%^</destinationTag^> >> CSSE-
2X.xml
ping -n 1 localhost >nul
goto Main
cls
Here is a snippet of the .XML I am working with, all others MUST remain the same. Just the "destinationTag" nodes need to be updated with %tags2%.
<reverseDirection>
<boolean>false</boolean>
<boolean>false</boolean>
</reverseDirection>
<loadWeightUSTons>0</loadWeightUSTons>
<destinationTag>EL</destinationTag>
<unitNumber>927453</unitNumber>
The iteration of destinationTags could be over 100 times in one XML file. There should be a loop process that I can use to update the said .XML file?
The main CMD program is running perfectly, the only issue is it's not updating the .XML file.
Any help is greatly appreciated.