我找不到这样做的方法(尝试通过 StackOverflow 搜索)。
我有一个格式化的 xml 文件,我必须按原样从中提取一个块(不修改格式、制表符、<、> 等。)例如,假设有一个文件名为some.xml
该块由以下内容分隔:
<!- Let us call this tag_begin -->
<Ask Ref_Ask="XXXYYYYY">
...
<!- Let us call this tag_end -->
</Ask>
我成功提取了 blockend 标记的开始行和结束行,但我不能将所有行长度都放入 result.txt 文件中:行停止在 127 个字符长度处:怎么了?
@echo off
Set Tag_Begin="<Ask Ref_Ask="
Set Tag_End="</Ask>"
set NB=XXXYYYY
set /A CPTE=0
set Line_Begin=
set Line_End=
Rem --- Find all possible start of block lines, and extract the good one set to Line_Begin
findstr /n /C:%Tag_Begin% some.xml | find /i "%NB%"> temporary.txt
for /f "tokens=1 delims=:" %%L in (temporary.txt) do set Line_Begin=%%L
Rem --- Finding the line order (from all possible start lines) which match the good one
findstr /n /C:%Tag_Begin% some.xml | findstr /n "%NB%"> temporary.txt
for /f "tokens=1 delims=:" %%O in (temporary.txt) do set order_begin=%%O
set /A order_begin-=1
Rem -- Looking for all possible end of block lines, and extract the "order_begin" one for Line_End
for /f "skip=%order_begin% tokens=1 delims=:" %%F in ('findstr /n /C:%Tag_End% some.xml') do set Line_End=%%F & goto away
:away
setlocal enabledelayedexpansion
for /f %%L in (some.xml) do (
set /A CPTE+=1
echo CPTE=!CPTE!
if !CPTE! GEQ %Line_Begin% if !CPTE! LEQ %Line_End% echo %%L >> result.txt
)
setlocal disabledelayedexpansion
del temporary.txt