I have to extract certain text from an XML file via a batch file. One of the parts I need to extract is between string tags (<string>example1</string>
) and the other is between data tags (<data>example2</data>
). Any ideas how? Thanks in advance!
我必须通过批处理文件从XML文件中提取某些文本。我需要提取的部分之一是字符串标记(
3 个解决方案
#1
3
@echo OFF
del output.txt
for /f "delims=" %%i in ('findstr /i /c:"<string>" xml_file.xml') do call :job "%%i"
goto :eof
:job
set line=%1
set line=%line:/=%
set line=%line:<=+%
set line=%line:>=+%
set line=%line:*+string+=%
set line=%line:+=&rem.%
echo.%line%>>output.txt
:eof
Output with OP's input file-
输出OP的输入文件 -
D:\>draft.bat
D:\>type output.txt
000000000@gmail.com
default
Web form password
www.instagram.com (000000000@gmail.com)
www.instagram.com
Cheers, G
#2
2
Try this:
@echo off
setlocal EnableDelayedExpansion
(for /F "delims=" %%a in ('findstr /I /L "<string> <data>" theFile.xml') do (
set "line=%%a"
set "line=!line:*<string>=!"
set "line=!line:*<data>=!"
for /F "delims=<" %%b in ("!line!") do echo %%b
)) > result.txt
#1
3
@echo OFF
del output.txt
for /f "delims=" %%i in ('findstr /i /c:"<string>" xml_file.xml') do call :job "%%i"
goto :eof
:job
set line=%1
set line=%line:/=%
set line=%line:<=+%
set line=%line:>=+%
set line=%line:*+string+=%
set line=%line:+=&rem.%
echo.%line%>>output.txt
:eof
Output with OP's input file-
输出OP的输入文件 -
D:\>draft.bat
D:\>type output.txt
000000000@gmail.com
default
Web form password
www.instagram.com (000000000@gmail.com)
www.instagram.com
Cheers, G
#2
2
Try this:
@echo off
setlocal EnableDelayedExpansion
(for /F "delims=" %%a in ('findstr /I /L "<string> <data>" theFile.xml') do (
set "line=%%a"
set "line=!line:*<string>=!"
set "line=!line:*<data>=!"
for /F "delims=<" %%b in ("!line!") do echo %%b
)) > result.txt