1

我需要执行以下操作:

  • 我有一个包含文本的 .xml 文件文件夹
  • 我需要搜索特定的 xml 对并提取它们的值
  • 我需要遍历该文件夹中的所有 .xml 文件,并将结果输出到仅包含我需要的值的单个文件中。

我将如何使用 .bat 文件来做到这一点。我有一些使用 .bat 文件的概念,但从来没有这么复杂的东西。

4

1 回答 1

1

也许如果您向我们展示 .xml 文件的一般格式和您想要的特定对,我们可以向您展示您想要的批处理文件。批处理文件被写入以特定固定方式处理文件,因此在其他格式文件上没有“通用”批处理解决方案,除非其他格式不灵活。

下面是使用批处理文件处理 .xml 文件的三个示例:

编辑 XML 文件

用于提取特定 XML 标记值的批处理文件

如何在批处理cmd中循环遍历xml值

以下批处理文件是实现您想要的示例,假设您想要的“xml对”与上面的第二个示例相同:

@echo off
rem I have a folder of .xml files with text in them
cd "C:\Documents and Settings\My Name\The Folder"
rem I need to iterate through all the .xml files in that folder and output the results to a single file with just the values I need. 
(for %%a in (*.xml) do (
   call :check_lines < "%%a"
)) > "The Single File.txt"
exit /b


rem I need to search for particular xml pairs and pull their values 
rem Seek for the start of Data tag
:check_lines
   set /P line=
if not "%line%" == "<DATA>" goto check_lines

rem Copy until the end of Data tag
set /P line=
:put_lines
    if "%line%" == "</DATA>" goto end_lines
    set /P line=%line% 
goto put_lines
:end_lines
echo/
exit /B
于 2013-01-04T02:03:00.910 回答