当我写这段代码时:
@echo off
setlocal EnableDelayedExpansion
set anotherVariable=New value
(for /F "delims=" %%a in (2.xml) do (
set "line=%%a"
set "newLine=!line:SelfBillingIndicator>=!"
if "!newLine!" neq "!line!" (
set "newLine=!line!"
echo !newLine!
set "newLine=<SourceID>Admin</SourceID>"
)
@echo !newLine!
)) > 3.xml
我的代码有问题,我需要 "newLine=<SourceID>Admin</SourceID>"
出现在 SelfBillingIndicator 上,但只出现在特定节点上。我在 xml 中有很多拥有 SelfBillingIndicator 的节点,我的程序替换了所有但我只需要替换内部<Invoice>
节点。看例子:
<Document>
<SelfBillingIndicator>0</SelfBillingIndicator>
<Document>
<Invoice>
<InvoiceNo>F 2013A/321</InvoiceNo>
<SelfBillingIndicator>0</SelfBillingIndicator>
</Invoice>