xml – Inno Setup – 如何在特定行中保存节点
发布时间:2020-12-16 23:07:05  所属栏目:百科  来源:网络整理 
            导读:我需要有关inno设置的帮助,我需要在特定行中保存一些xml节点,但我不知道如何. 这是我的代码 procedure SaveValueToXML(const AFileName,APath,AValue: string);var XMLNode: Variant; XMLDocument: Variant; begin XMLDocument := CreateOleObject('Msxml2.D
                
                
                
            | 
 我需要有关inno设置的帮助,我需要在特定行中保存一些xml节点,但我不知道如何. 
  
  这是我的代码 procedure SaveValueToXML(const AFileName,APath,AValue: string);
var
  XMLNode: Variant;
  XMLDocument: Variant;  
begin
  XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0');
  try
    XMLDocument.async := False;
    XMLDocument.load(AFileName);
//    if (XMLDocument.parseError.errorCode <> 0) then
//      MsgBox('Install the software. ' +
//        XMLDocument.parseError.reason,mbError,MB_OK)
//    else
    begin
      XMLDocument.setProperty('SelectionLanguage','XPath');
      XMLNode := XMLDocument.selectSingleNode(APath);
      XMLNode.text := AValue;
      XMLDocument.save(AFileName);
    end;
  except
    MsgBox('Install the software',MB_OK);
  end;
end;
function NextButtonClick(PageID: Integer): Boolean;
var
  XMLFile: string;
begin
  Result := True;
  if (PageId = wpFinished) then
  begin
    XMLFile := ExpandConstant('{pf}Hell Config.xml');
    if FileExists(XMLFile) then
    begin
      SaveValueToXML(XMLFile,'//@param',PEdit.Text);  //PEdit.text is from a custom input text box in the installer,ignore.
      SaveValueToXML(XMLFile,'//@path',ExpandConstant('{reg:HKCUSOFTWARECraps,InstallPath}Test.exe'));
    end;
  end;
end;这是我的XML文件: <?xml version="1.0" encoding="UTF-8"?>
<stuffs>
        <stuff ident="555" path="C:Program Files (x86)Other thingOther.exe" param="-alive" display="1" priority="0"/>
        <stuff ident="666" path="C:Program Files (x86)Crapstest.exe" param="-dead" display="1" priority="0"/>    
</stuffs>问题是我的脚本总是写在第一行.我需要的是始终将节点保存在以< stuff ident =“666”开头的行中 提前致谢! 解决方法
 您将需要使用设置文本属性的 
  setAttribute方法.以下是修改节点属性值的过程:procedure SaveAttributeValueToXML(const AFileName,AAttribute,AValue: string);
var
  XMLNode: Variant;
  XMLDocument: Variant;  
begin
  XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.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,MB_OK)
    else
    begin
      XMLDocument.setProperty('SelectionLanguage','XPath');
      XMLNode := XMLDocument.selectSingleNode(APath);
      XMLNode.setAttribute(AAttribute,AValue);
      XMLDocument.save(AFileName);
    end;
  except
    MsgBox('An error occured!' + #13#10 + GetExceptionMessage,MB_OK);  
  end;
end;以下是如何查询其ident参数值为666且其param属性值将更改为-alive的节点: SaveAttributeValueToXML('d:File.xml','//stuffs/stuff[@ident=''666'']','param','-alive');有关此处使用的XPath查询的详细信息,请参阅例如到 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! | 
