Var
iList, tmpPosB, tmpPosE, tmpLen: Integer;
tmpEntry, tmpValue, tmpFile: String;
tmpList: TStringList;
Const
// 1
ctMainB = '';
ctMainE = '';
ctOutputPath = 'C:\Test\Customer\Out\'; // must end with \
Begin
psExitCode:= 0;
// ... add your code here
tmpFile := psFilePath + psFileName;
psLogWrite(1, '', 'Load Xml File: ' + tmpFile);
tmpList := TStringList.Create;
Try
Try
tmpList.LoadFromFile(tmpFile);
for iList := 0 To (tmpList.Count-1) do
Begin
tmpEntry := tmpList.Strings[iList];
tmpLen := length(ctMainB);
tmpPosB := Pos(AnsiLowerCase(ctMainB), AnsiLowerCase(tmpEntry));
tmpPosE := Pos(AnsiLowerCase(ctMainE), AnsiLowerCase(tmpEntry));
If (tmpPosB <> 0) And (tmpPosE >= (tmpPosB + tmpLen)) Then
Begin
tmpValue := Copy(tmpEntry, tmpPosB+tmpLen, tmpPosE-tmpPosB-tmpLen);
psLogWrite(1, '', 'Value: ' + tmpValue);
If tmpValue = '1' Then
tmpList.Strings[iList] := psStringReplace(tmpEntry, ctMainB+tmpValue+ctMainE, ctMainB+'Good'+ctMainE)
Else
tmpList.Strings[iList] := psStringReplace(tmpEntry, ctMainB+tmpValue+ctMainE, ctMainB+'NoGood'+ctMainE);
psLogWrite(1, '', 'Entry changed to: ' + tmpList.Strings[iList]);
// Set Result
psExitCode:= 1;
// Break; // We will not break here, maybe there are more than one entries
End;
End;
// Save to File
If psExitCode = 1 Then
Begin
Try
psLogWrite(1, '', 'Save Xml to: ' + ctOutputPath+psfileName);
tmpList.SaveToFile(ctOutputPath + psfileName);
Except
psLogwrite(1, '', 'Exception SaveToFile: ' + ctOutputPath+psfileName);
End;
End
Else
psLogwrite(1, '', 'Skip, no valid combination of ' + ctMainB + ' and ' + ctMainE + ' was found in file ' + tmpFile);
Except
psLogwrite(1, '', 'Exception LoadFromFile: ' + tmpFile);
End;
Finally
tmpList.Free;
End;
End.