Windows 使用批处理脚本在XML文件中增加属性值
我试图编辑一个xml文件并增加一个名为“pageindex”的属性值 xml文件中的数据如下所示Windows 使用批处理脚本在XML文件中增加属性值,windows,batch-file,cmd,taleo,Windows,Batch File,Cmd,Taleo,我试图编辑一个xml文件并增加一个名为“pageindex”的属性值 xml文件中的数据如下所示 ?xml version="1.0" encoding="UTF-8"?> <quer:query productCode="RC1700" model="http://www.taleo.com/ws/tee800/2009/01" projectedClass="Candidate"
?xml version="1.0" encoding="UTF-8"?>
<quer:query productCode="RC1700" model="http://www.taleo.com/ws/tee800/2009/01" projectedClass="Candidate" locale="en" alias="MainQuery" mode="T-XML" largegraph="true"
preventDuplicates="false" attributes="pageindex=1,pagingsize=350"
xmlns:quer="http://www.taleo.com/ws/integration/query">
<quer:subQueries/><quer:projections>
<quer:projection><quer:field path="Number"/>
</quer:projection><quer:projection><quer:field path="FirstName"/>
?xml version=“1.0”encoding=“UTF-8”>
这是我创建的批处理脚本,但值“1”没有增加
@echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "_FILE=pagexml" & rem // (input file; `%~1` is the first argument)
set "_INI=<quer:query productCode="RC1700" model="http://www.taleo.com/ws/tee800/2009/01" projectedClass="Candidate" locale="en" alias="MainQuery" mode="T-XML" largegraph="true" preventDuplicates="false" attributes=" &
set "_TAG=pageindex=" & rem // (opening tag)
rem // Loop over all (non-empty) lines of the input file:
(for /F "usebackq delims=" %%L in ("%_FILE%") do (
rem // Store current line string:
set "LINE=%%L"
rem // Toggle delayed expansion to avoid troubles with `!`:
setlocal EnableDelayedExpansion
rem // Split off opening tag from line string:
set "TEST=!LINE:*%_TAG%=!"
rem // Check whether opening tag has been found:
if not "!TEST!"=="!LINE!" (
rem // Opening tag found, hence split off closing tag:
for /F "tokens=1* eol=, delims=, " %%S in ("!TEST!") do (
rem // Get extracted number and increment it:
set /A "NUM=%%S+1"
rem // Return rebuild line with incremented number:
echo( !_INI!!_TAG!!NUM!^,%%T
)
) else (
rem // Opening tag not found, hence return original line:
echo(!LINE!
)
endlocal
))>pageTmp.xml
copy /v /y "pageTmp.xml" "page.xml"
del "pageTmp.xml"
@echo关闭
setlocal EnableExtensions DisableDelayedExpansion
rem//在此处定义常量:
设置“_FILE=pagexml”&rem//(输入文件,`%~1`是第一个参数)
设置“\u INI=第一个问题是您的搜索字符串\u TAG=pageindex=
在set“TEST=”中使用时!行:*%\u标记%=!“
,这将导致
==1,pagingsize=350"
等号加倍,因为serach表达式不能包含等号,等号始终用于分割搜索和替换部分。
您可以搜索pageindex
,并将其替换为=
因此,%%S
包含==1
并且设置/a NUM===1+1
失败
您可以通过将中的delims=,
更改为delims=,=
来解决此问题
for /F "tokens=1* eol=, delims=,= " %%S in ("!TEST!") do (
我看到了这段代码…;-)无论如何,要编辑XML数据,您应该使用本机支持的语言(例如PowerShell、VBScript、JavaScript)…给定的文本似乎不是有效的XML文件。请使用[XML](获取内容-路径“C:\src\t\query.XML”)尝试PowerShell
。
for /F "tokens=1* eol=, delims=,= " %%S in ("!TEST!") do (