我想在Windows 10上创建一个批处理,它将计算特定标记在XML文件中出现的次数。 以下是我找到并尝试过的代码。它应该将值放在另一个文件中的一组标记之间,但这在我的情况下不起作用:
@echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%a in (test.xml) do (
set "line=%%a"
for %%X in (^"^
% Do NOT remove this line %
^") do for /F "delims=" %%b in ("!line:>=%%~X!") do (
if /I "!field!" equ "<LineCde" for /F "delims=<" %%c in ("%%b") do echo %%c >> file2.txt
set "field=%%b"
)
)
Pause
我的XML文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<Document><Mouvement>
<Commande>
<RefCommande>xxx</RefCommande>
<SystemRefCde>xx</SystemRefCde>
<StatusCommande>
<CodeStatusOpCommande>xxx</CodeStatusOpCommande>
<DateStatusOpCommande>04/09/2017</DateStatusOpCommande>
<TimeStatusOpCommande>09:13:58</TimeStatusOpCommande>
</StatusCommande>
<LineCde>
<RefLineCde>xxx</RefLineCde>
<SystemRefLigneCde>32R</SystemRefLigneCde>
<TimeHour>
<TypeDate>xxx</TypeDate>
<ValueDate>04/09/2017</ValueDate>
<TimeDate>00:00:00</TimeDate>
</TimeHour>
</LineCde>
</Commande>
</Mouvement></Document>
任何人都可以帮我吗?代码在Windows 7中工作。谢谢
用于:
findstr /ip /D:"\Vi\Defect+Evo\Traduction\testB"
*.xml >> log-it.txt
@echo off
setlocal EnableDelayedExpansion
set "string=findstr /R /N "^^" log-it.txt | find /C "/LineCde""
for /f %%a in ('!string!') do set count=%%a
echo %count%
del /Q log-it.txt
答案 0 :(得分:1)
这将在xxx
文件中搜索test.xml
并回显找到的次数。
@echo off
setlocal EnableDelayedExpansion
set "string=findstr /R /N "^^" test.xml | find /C "xxx""
for /f %%a in ('!string!') do set count=%%a
echo %count%
使用与上面相同的脚本,但我们搜索目录中的所有xml
文件,然后将它们全部传输到日志文件并回显日志文件的总和。
@echo off
findstr /ip /c:"xxx" *.xml >> log-it.txt
setlocal EnableDelayedExpansion
set "string=findstr /R /N "^^" log-it.txt | find /C ":""
for /f %%a in ('!string!') do set count=%%a
echo %count%
del /Q log-it.txt
编辑:
根据您的评论。
findstr /ip /d:\Vi\Defect+Evo\Trad\testB\te *.xml
永远不会奏效。你不能删除c:
这不是路径,这是要搜索的字符串。
@echo off
findstr /ip /c:"/LineCde" D:\Vi\Defect+Evo\Traduction\testB\*.xml >> log-it.txt
setlocal EnableDelayedExpansion
set "string=findstr /R /N "^^" log-it.txt | find /C "/LineCde""
for /f %%a in ('!string!') do set count=%%a
echo %count%
del /Q log-it.txt
将其分解,以便了解正在发生的事情:
findstr /ip /c:"/LineCde" D:\Vi\Defect+Evo\Traduction\testB\*.xml >> log-it.txt
#Findstr searches for a string
# /i makes the search non-case sensitive.
# /p Skip files with non-printable characters.
# /c: specifies the string to find. in this case "/LineCde"
# then we specify where to search (D:\...) and what to search (*.xml)
# >> we pipe it to a log file. (log-it.txt)
setlocal EnableDelayedExpansion
# enable Delayed expansion
set "string=findstr /R /N "^^" log-it.txt | find /C "/LineCde""
# Now we do the same, we read from the logfile as we wrote each of the XML entries and create them in the logfile, we just count all the entries together.
for /f %%a in ('!string!') do set count=%%a
# once we found each line number, we set it as a variable
echo %count%
# we print that variable to screen
del /Q log-it.txt
# Now we delete the file because we do not need it and next time we will create a new file.
答案 1 :(得分:0)
这个单线程怎么样?
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
ImageButton img = sender as ImageButton;
GridViewRow grv = img.Parent as GridViewRow;
string[] textboxValues = Request.Form.GetValues("DynamicTextBox"); //Request.Form["txtSpeciality"];
JavaScriptSerializer serializer = new JavaScriptSerializer();
this.Values = serializer.Serialize(textboxValues);
if (e.CommandName == "mybutton")
{
GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer;
int rowIndex = gvr.RowIndex;
Label Itemid = (Label)GridView1.Rows[rowIndex].FindControl("lblID");
ID1 = (Itemid).Text;
Session["ID"] = ID1;
EditSubjectItem();
string Role = string.Empty;
FileUpload fil1 = grv.FindControl("fil1") as FileUpload;
fil1.AllowMultiple = false;
}
//added
}