First, I'm reallly beginner at batch or cmd syntax. So my syntax looks very foolish, please read this with a broad mind. Thx!
I want to get a value from my specific local xml file and i want to get a part of that value. Because, I have to compare with that value and specific other value.
well, I found it with all my effort. But I couldn't 100%. Please read this code.
fc /b "C:\e\e.xml" "C:\Users\%username%\Documents\e\e.xml" return errorlevel
set usr_name=%username:~-2,2%
set _name=
IF %ERRORLEVEL% EQU 0 (
for /f "tokens=2delims=<>" %%i in ('find "KEY" "c:\e\e.xml"') do echo %%i
REM echo ^<username^>%usr_name%^</Setup_Date^>^<substr^>%%i^</substr^> > "C:\e\test.xml"
echo ^<username^>%usr_name%^</username^>^<substr^>%_name%^</substr^> > "C:\e\test.xml"
if %%i:~-4,2 == %usr_name% (
REM echo ^<username^>%usr_name%^</username^>^<substr^>%%i:~-4,2%^</substr^> > "C:\e\test.xml"
echo YES
ELSE (
echo NO
cscript no.vbs
)
And this is my xml file. I want to get D4 of KEY tag (D4, It occupies 2 letters from the 4th from the back.)
<Date>2020-08-13</Date><Setup>Zs#ol9fEV9pA</Setup>
<KEY>WY(T5XD4h4<KEY>
the problem is this
REM echo ^<username^>%usr_name%^</Setup_Date^>^<substr^>%%i^</substr^> > "C:\e\test.xml"
echo ^<username^>%usr_name%^</username^>^<substr^>%_name%^</substr^> > "C:\e\test.xml"
if value i = abcdef I can get the value from xml file abcdef, using REM sentence. But I can't get the part of variable i.
when i use second sentence or other expressions such as %i:~-4,2% etc. (because i want to compare using that part of value. %i:~-4,2% = cd) I can't print any values, just print nothing.
Is there a way to solve this problem? As i said earlier, I have a very tiny knowledge about batch, So let me know everything you know. Or if this way couldn't solve without using other library or xpath.bat, please tell me as I have to find another way.
Thank you.