2013-01-03 272 views
1

我需要執行以下操作:批處理文件命令/處理

  • 我的文字.xml文件的文件夾在其中
  • 我需要尋找特定的XML對和拉他們的價值觀
  • 我需要遍歷該文件夾中的所有.xml文件,並使用我需要的值將結果輸出到單個文件。

我該如何去做與.bat文件。我有一些使用.bat文件的概念,但從來沒有這麼複雜。

+0

建議您考慮使用[tag:powershell],而不是。它有很多對XML的支持。 – David

回答

1

也許如果你向我們展示你的.xml文件的一般格式和你想要的特定對,我們可以向你展示一個批量文件,它可以做你想做的。批處理文件以特定的固定方式寫入處理文件,所以在其他格式文件上不存在「通用」批處理解決方案,除非其他格式不靈活。

下面有一個批處理文件.xml文件處理的三個例子:

Editing XML files

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