DOS批处理:追加以独特的TXT文件的XML标记 [英] DOS batch : append XML tags in unique TXT file
问题描述
我需要列出&LT的内容; AAA>< / AAA>从多个XML文件
XML标记成一个独特的TXT结果文件。说我有一个文件夹D:/文件夹。一个包含多个XML文件
下面是我的code:
关闭@echoCD D:/在(文件夹/ *。xml的)%% f执行( FOR / F %%一个在(%% f)作( FOR / Fdelims =< AAA>< / AAA>令牌= 2%% b在('回声%%一个^ | Findstr工具/ R< AAA>中)做回声%% B&GT ;>的Result.txt ))
在code做第一个XML文件中的工作,但再找不到其他的...壳牌窗口显示错误消息(见附表形象,对不起,这是法语)。
@ECHO OFF
SETLOCAL
SETsourcedir = U:\\ sourcedirFOR / F令牌= 3delims =<>中%%一个IN('FINDSTR / L / C:< AAA>中%sourcedir%\\ *。xml的^ | FINDSTR / L / C:< / AAA>中)DO ECHO %%一GOTO:EOF
您将需要更改 sourcedir
的设置,以适应您的情况。
您不显示使用你的真实标签是什么; delims =
建立了一套分隔符,分隔符不是字符串。
您可能需要改变令牌= 3
到令牌= 2
如果你的 AAA
标记不缩进。如果它可以或可以不被缩进,那么程序将需要改变少许。
这是可能的,在附近的标签的第二过滤器是不需要的。一切都取决于你有没有告诉我们 - 你的实际的布局
这应该工作如果有问题的行
空格< AAA-GT; stingyouwant< / AAA>凡是
请注意 \\
针对目录的分隔符; /
为命令交换机。
I need to list the content of <AAA></AAA>
XML tags from several XML files into a unique TXT results file. Say I have a folder 'D:/folder' that contains several XML files.
Here is my code :
@echo off
cd D:/
for %%f in (folder/*.xml) do (
for /f %%a in (%%f) do (
for /f "delims=<AAA></AAA> tokens=2" %%b in ('echo "%%a" ^| Findstr /r "<AAA>"') do echo %%b >> result.txt
)
)
The code is doing the job for the first XML file but then cannot find the other ones... The Shell window shows error messages (see attached image ; sorry, it's in french).
@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
FOR /f "tokens=3delims=<>" %%a IN ('findstr /L /c:"<AAA>" "%sourcedir%\*.xml"^|findstr /L /c:"</AAA>"') DO ECHO %%a
GOTO :EOF
You would need to change the setting of sourcedir
to suit your circumstances.
You don't show use what your real tags are; "delims="
establishes a set of delimiter characters, not delimiter strings.
You may need to vary tokens=3
to tokens=2
if your AAA
tag is not indented. If it may or may not be indented, then the routine would need to be varied a little.
It's probable that the second filter on the close-tag is not required. All depends on what you haven't told us - your actual layout.
This should work if the lines in question are
spaces<AAA>stingyouwant</AAA>whatever
Please also note \
for directory-separators; /
for command-switches.
这篇关于DOS批处理:追加以独特的TXT文件的XML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!