使用批处理文件在现有xml文件中添加Root标记

时间:2016-01-08 15:05:18

标签: xml batch-file

我正在尝试使用批处理文件将多个xml文件合并到单个xml文件中。在组合时我想添加根标签,例如> Master_File>为了组合xml.I写了一个批处理文件来组合,但我无法添加根标记。

批处理文件:

del combined.xml
REM set count to 1
set cnt=1
REM for each file that matches *.xml
for %%i in (*.xml) do (
REM if count is 1 it's the first time running
if !cnt!==1 (
REM push the entire file complete with header into combined.xml - this will also create combined.xml
for /f "delims=" %%j in ('type "%%i"') do echo %%j >> combined.xml
REM otherwise, make sure we're not working with the combined file and
 ) else if %%i NEQ combined.xml (
REM push the file without the header into combined.xml
for /f " delims=" %%j in ('type "%%i"') do echo %%j >> combined.xml
)
REM increment count by 1
set /a cnt+=1
)

当前产生的xml:

<xml1>
   <a>...</a>
</xml1>
<xml2>
   <b>...</b>
</xml2>
  <xml3>
   <c>...</c>
</xml3>

结合后的预期输出xml是

<Master_File>
<xml1>
   <a>...</a>
</xml1>
<xml2>
   <b>...</b>
</xml2>
  <xml3>
   <c>...</c>
</xml3>
</Master_File>

任何人都可以帮助实现这一目标!

0 个答案:

没有答案