我有这个脚本,用来读取 xml 文件。该文件包含坐标,我想列出坐标:
@echo off
setlocal EnableDelayedExpansion
FOR %%K IN (*.xml) DO (
SET K=%%K
SET K=!K:~0,-4!
SET "prep=0"
REM READ DATA
FOR /F "tokens=*" %%X IN (!K!.kml) DO (
if !prep! == 1 (
echo %%X
pause
FOR /F %%L IN ("%%X") DO (
SET L=%%L
IF NOT "!L:~0,1!" == "<" (
echo %%L
)
)
SET "prep=0"
)
if "%%X" == "<coordinates>" ( SET "prep=1" )
)
)
我得到了这些结果:
14.63778004128814,49.50141683426452,0 14.63696238385996,49.48348965654706,0 14.6
8840586504191,49.47901033971912,0 14.68589371304878,49.49939179836829,0 14.63778
004128814,49.50141683426452,0 </coordinates>
Press and key to continue...
14.63778004128814,49.50141683426452,0
Press and key to continue...
首先,您会看到带有坐标的线。其次,在第三个循环中,打印了坐标。但是我只打印了一对坐标...如果我再次按下一个键,则批处理完成而不打印下一列。你能帮我吗?
编辑 发布答案后,我有问题1)我们可以使用这个:
SET LF=^
setlocal EnableDelayedExpansion
... (next code) ...
set "var=!var: =%LF%!"
所以当没有延迟的LF变量时,我们可以嵌入它。或不?
2)为什么在你的代码中
for %%L in ("!LF!") do set "X=!X: =%%~L!"
你有没有使用 %%~L 而不仅仅是 %%L