我需要通过批处理从XML文件中提取特定的文本。我需要提取的部分是在字符串标签(<string>example1</string>
)和数据标签(<data>example2</data>
)之间的文本。你有什么建议吗?谢谢!
我需要通过批处理从XML文件中提取特定的文本。我需要提取的部分是在字符串标签(<string>example1</string>
)和数据标签(<data>example2</data>
)之间的文本。你有什么建议吗?谢谢!
@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
D:\>draft.bat
D:\>type output.txt
000000000@gmail.com
default
Web form password
www.instagram.com (000000000@gmail.com)
www.instagram.com
你好,G
字符串 字符串 数据 字符串 字符串 字符串字符串 字符串 字符串 字符串 数据 字符串 字符串 字符串字符串 字符串 字符串 字符串 数据 字符串 字符串 字符串字符串 字符串
- user1599051试试这个:
@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
<string>
标签之间的内容,但无法提取<data>
标签之间的内容。 - user1599051