Ich habe diese XML-Datei:Wie werden zwei spezifische Elementwerte in einer XML-Datei in einem bestimmten Elementblock ersetzt?
<?xml version = "1.0" encoding = "UTF-8"?>
<ApplicationsToCheck xmlns = "http://www.tibco.com/schemas/StoreAppraisalSvc/SharedResources/Schemas/HealthCheck/Schema.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.tibco.com/schemas/StoreAppraisalSvc/SharedResources/Schemas/HealthCheck/Schema.xsd ../Schemas/HealthCheck/HealthCheckSchema.xsd">
<Application>
<ApplicationName>AccountsPayableAdapter</ApplicationName>
<HAMode>NA</HAMode>
<AppPortList>
<HostPort>
<HostName>ESBBWSVCP01</HostName>
<Port>57611</Port>
</HostPort>
</AppPortList>
</Application>
<Application>
<ApplicationName>CorpCredit</ApplicationName>
<HAMode>LB</HAMode>
<AppPortList>
<HostPort>
<HostName>ESBBWSVCP01</HostName>
<Port>57250</Port>
</HostPort>
<HostPort>
<HostName>ESBBWSVCP02</HostName>
<Port>57250</Port>
</HostPort>
</AppPortList>
</Application>
<Application>
<ApplicationName>CustomerSvcV1_0</ApplicationName>
<HAMode>LB</HAMode>
<AppPortList>
<HostPort>
<HostName>ESBBWSVCP01</HostName>
<Port>57632</Port>
</HostPort>
<HostPort>
<HostName>ESBBWSVCP01</HostName>
<Port>57641</Port>
</HostPort>
<HostPort>
<HostName>ESBBWSVCP02</HostName>
<Port>57632</Port>
</HostPort>
<HostPort>
<HostName>ESBBWSVCP02</HostName>
<Port>57641</Port>
</HostPort>
</AppPortList>
</Application>
</ApplicationsToCheck>
Ich mag die Werte von zwei Host-Namen mit einem Windows-Skript Elemente ändern, schließlich ESBBWSVCP03
statt ESBBWSVCP01
und ESBBWSVCP04
statt ESBBWSVCP02
in der Datei Wert hat, aber nur innerhalb Element ApplicationName mit Wert CorpCredit
.
EDIT: Hier ist, was ich versucht habe:
@echo off
setlocal enabledelayedexpansion
set sourcefile=d:\CorpApplicationsToCheck.xml
set tempfile=d:\tempfile.txt
set oldtoken=ESBBWSVCP01
set newtoken=ESBBWSVCP03
type nul>%tempfile% for /f "tokens=*" %%l in (%sourcefile%) do (
set line=%%l
set line=!line:%oldtoken%=%newtoken%!
echo !line!>>tempfile.txt
)
del %sourcefile%
move %tempfile% %sourcefile%
Jede Hilfe wäre sehr willkommen.