【发布时间】:2013-12-06 03:17:20
【问题描述】:
我需要从文件夹中所有 xml 文件中的特定 xml 标记中提取值,并在 csv 文件的 2 个单独列中导出值和文件名(不带 ext)。我已经尝试过零运气。
xml 看起来像这样:
<ICSMXML xmlns="http://www.icsm.com/icsmxml" version="1.0">
<Header>
<MsgDelivery>
<To>
<Credential>
<Domain>ICSMID</Domain>
<Identity>11</Identity>
</Credential>
</To>
<From>
<Credential>
<Domain>DUNS</Domain>
<Identity>039576814</Identity>
</Credential>
</From>
<Sender>
<Credential>
<Domain>DUNS</Domain>
<Identity>039576814</Identity>
</Credential>
<UserAgent />
</Sender>
</MsgDelivery>
<MsgHeader>
<MessageId>10000095713</MessageId>
<Timestamp>04/12/2013 10:24:00 AM</Timestamp>
我需要从文件夹中找到的任何 xml 文件中解析 MessageId 的值,并将其与原始文件名(不带分机)一起放入 csv 文件中。最好在第 1 列中包含值,在第 2 列中包含文件名 w.o ext。
@echo off
call :check_lines < %1 > "%~N1.xml"
exit /b
REM Seek for the start of Data tag
:check_lines
set /P line=
if not "%line%" == "<MessageId>" goto check_lines
REM Copy until the end of Data tag
set /P line=
:put_lines
if "%line%" == "</MessageId>" goto end_lines
set /P line=%line%
goto put_lines
:end_lines
echo %line%
>>Message.csv
【问题讨论】:
标签: xml batch-file