我必须通过批处理文件从XML文件中提取某些文本。我需要提取的部分之一是字符串标记(<string>example1</string>
),另一部分是数据标记(<data>example2</data>
)之间。有什么想法?提前谢谢!
答案 0 :(得分: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
使用OP的输入文件输出 -
D:\>draft.bat
D:\>type output.txt
000000000@gmail.com
default
Web form password
www.instagram.com (000000000@gmail.com)
www.instagram.com
干杯,G
答案 1 :(得分:2)
试试这个:
@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
答案 2 :(得分:1)
检查xpath.bat脚本:
call xpath.bat "xml.xml" "//data"