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

查看:31
本文介绍了使用批处理代码批量格式化 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:Usersuser>for /d %%X in (C:<C:UsersuserDesktopqq>*)
do (c:<C:UsersuserDownloads	idy-5.6.0-vc14-32b	idy-5.6.0-vc14-
32bin>	idy.exe -m -xml -config c:<C:UsersuserDownloads	idy-5.6.0-
vc14-32b	idy-5.6.0-vc14-32bin>	idycfg.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%Desktopqq"
Set "TidyPath=%UserProfile%Downloads	idy-5.6.0-vc14-32b	idy-5.6.0-vc14-32bin"
For /D %%A In ("%FilePath%*") Do For %%B In ("%%A*.xml") Do "%TidyPath%	idy.exe" -m -xml -i "%%B"

从命令提示符:

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

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

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