批处理文件命令/处理
问题描述:
我需要执行以下操作:批处理文件命令/处理
- 我的文字.xml文件的文件夹在其中
- 我需要寻找特定的XML对和拉他们的价值观
- 我需要遍历该文件夹中的所有.xml文件,并使用我需要的值将结果输出到单个文件。
我该如何去做与.bat文件。我有一些使用.bat文件的概念,但从来没有这么复杂。
答
也许如果你向我们展示你的.xml文件的一般格式和你想要的特定对,我们可以向你展示一个批量文件,它可以做你想做的。批处理文件以特定的固定方式写入处理文件,所以在其他格式文件上不存在“通用”批处理解决方案,除非其他格式不灵活。
下面有一个批处理文件.xml文件处理的三个例子:
A batch file to extract the value of a specific XML tag
How to loop through xml values in a batch cmd
下面的批处理文件是实现你想要的一个例子,假设您想要的“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
建议您考虑使用[tag:powershell],而不是。它有很多对XML的支持。 – David