Reputation: 265
I have an xml file that has values resembling this:
<Editable default="XXX07770004183" description="Station Id" name="MachineID.PSID" regex="^XXX[a-zA-Z0-9]{4}[0-9]{4}[a-zA-Z0-9]{3}$"/>
<Editable default="17" description="Machine Number" name="MachineID.MachineID" regex="^[0-9]+$"/>
<Editable default="32" description="Asset number" name="MachineID.AssetNumber" regex="^[0-9]+$"/>
<Editable default="AAALLL74" description="Serial number" name="MachineID.SerialNumber" regex="^[a-zA-Z0-9]+$"/>
I'd like to get the value of asset number (32 in this example) and save it to a variable. The asset number can be 5 digits in length.
This is Windows batch with findstr.
findstr /C:MachineID.AssetNumber Static.Settings.xml but this only matches the entire line:
<Editable default="32" description="Asset number of the machine." name="MachineID.AssetNumber" regex="^[0-9]+$"/>
Any hints are appreciated!
Upvotes: 0
Views: 84
Reputation: 56155
use a for /f
loop to "disassemble" a line:
for /f tokens^=2^ delims^=^" %%a in ('findstr /C:"MachineID.AssetNumber" Static.Settings.xml') do set asset=%%a
echo %asset%
The strange syntax instead of "tokens=2 delims=""
is neccessary to correctly process the quote.
Upvotes: 1