使用批处理代码来批量xml格式化? [英] Using batch code to mass xml formatting?

查看:320
本文介绍了使用批处理代码来批量xml格式化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含50个子文件夹的文件夹,每个文件夹包含2个xml文件

I have a folder that contains 50 subfolders each one of these contains 2 xml files

O_DATA.xml
S_DATA.xml

由于它们出现在记事本中的一行中,因此我必须修复格式.

Since they appear in one line in Notepad, I have to fix the formatting.

我从一个类似的问题中发现了以下代码:

I have found from a similar question here this code:

@echo off
setlocal EnableDelayedExpansion

rem Create a variable with spaces
set "spaces= "
for /L %%i in (1,1,5) do set "spaces=!spaces!!spaces!"

rem Read the line
for /F "delims=" %%a in (input.txt) do set "line=%%a"

set level=0
:nextTag
   rem Separate first tag from line
   for /F "tokens=1* delims=<" %%a in ("!line!") do (
      set "tag=%%a"
      set "line=%%b"
   )
   rem Show first tag in one separate line
   if "%tag:~0,1%" equ "/" set /A level-=5
   echo !spaces:~0,%level%!^<!tag!
   if "%tag:~0,1%" neq "/" set /A level+=5
if defined line goto nextTag

批处理脚本用于格式化XML文件|搜索字符串并将其注释掉

但这不是一回事,我也一直在研究这个答案,但我对批处理代码了解不多.

But it is not really the same thing and also I've been studying this answer but I don't know much about batch code.

所以问题是如何制作将在该文件夹结构中运行的批处理脚本并将其格式化?

So the question is how to make a batch script that will run through that folder structure and format them?

更新: 我试过了:

C:\Users\user>for /d %%X in (C:\<C:\Users\user\Desktop\qq>\*)
do (c:\<C:\Users\user\Downloads\tidy-5.6.0-vc14-32b\tidy-5.6.0-vc14-
32b\bin>\tidy.exe -m -xml -config c:\<C:\Users\user\Downloads\tidy-5.6.0-
vc14-32b\tidy-5.6.0-vc14-32b\bin>\tidycfg.ini %%X\<O_DATA>.xml)

gives: %%X was unexpected at this time.

如果我删除一个%,则会给出:

and if I delete one % gives:

< was unexpected at this time.

ini文件具有:

indent:yes
indent-attributes:yes

推荐答案

以下内容假定您的子文件夹都在qq目录中,并且您在提供的位置也使用tidy.exe.

The following assumes that your subfolders are all inside the qq directory, and you are using tidy.exe, also in the location provided.

从批处理文件中:

@Echo Off
Set "FilePath=%UserProfile%\Desktop\qq"
Set "TidyPath=%UserProfile%\Downloads\tidy-5.6.0-vc14-32b\tidy-5.6.0-vc14-32b\bin"
For /D %%A In ("%FilePath%\*") Do For %%B In ("%%A\*.xml") Do "%TidyPath%\tidy.exe" -m -xml -i "%%B"

从命令提示符处:

For /D %A In ("%UserProfile%\Desktop\qq\*") Do For %B In ("%A\*.xml") Do "%UserProfile%\Downloads\tidy-5.6.0-vc14-32b\tidy-5.6.0-vc14-32b\bin\tidy.exe" -m -xml -i "%B"

这篇关于使用批处理代码来批量xml格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆