Inno 设置:提取 XML 节点并显示它

Inno setup: Extract XML node and show it

我有以下代码,我想将其提取为纯文本,但我做不到。

代码有效,但我需要在 ExpandConstant 字段中显示它。 我尝试了几种方法,但到目前为止都没有成功。

    function LoadValueFromXML(const AFileName, APath: string): string;
    var
      XMLNode: Variant;
      XMLDocument: Variant;  
    begin
      Result := '';
      XMLDocument := CreateOleObject('Msxml2.DOMDocument.3.0');
      try
        XMLDocument.async := False;
        XMLDocument.load(AFileName);
        if (XMLDocument.parseError.errorCode <> 0) then
          MsgBox('The XML file could not be parsed. ' + 
            XMLDocument.parseError.reason, mbError, MB_OK)
        else
        begin
          XMLDocument.setProperty('SelectionLanguage', 'XPath');
          XMLNode := XMLDocument.selectSingleNode(APath);
          Result := XMLNode.text;
        end;
      except
        MsgBox('An error occured!' + #13#10 + GetExceptionMessage, mbError, MB_OK);
      end;
    end;

    procedure CurPageChanged(CurPageID: Integer);
    begin
      if CurPageID = CustomPageID then
        CustomEdit.Text := LoadValueFromXML('C:\Games\World_of_Tanks_test\WoTLauncher.xml', '//info/patch_info_urls/item');
    end;

   procedure ClienteWot();
    var
      StaticText: TNewStaticText;
    begin
      StaticText := TNewStaticText.Create(WizardForm);
      StaticText.Parent := WizardForm.SelectComponentsPage;
      StaticText.Left := 425;
      StaticText.Top := ScaleY(40);
      StaticText.Font.Style := [fsBold];
      //StaticText.Font.Color := clRed;
      StaticText.Caption := ExpandConstant('Cliente WOT: -->>> Show XML Url <<<---');
    end;

如果要将值内联到可以传递给 ExpandConstant function call, you can use e.g. the Format 函数的字符串中:

var
  ...
  URL: string;
begin
  ...
  URL := LoadValueFromXML('C:\MyFile.xml', '//node/subnode');
  StaticText.Caption := ExpandConstant(Format('{username} %s', [URL]));
end;

上面的伪代码示例读取XML值并将返回值赋给URL变量。然后它计算第二行的内部语句:

Format('{username} %s', [URL])

URL 字符串值内联到给定字符串中(代替 %s)并生成如下字符串:

'{username} www.example.com'

然后此字符串由 ExpandConstant 函数调用(外部语句)处理并分配给静态文本标题,例如:

'MyUserName www.example.com'