Inno Setup-如何在特定行中保存节点 [英] Inno Setup - How to save a node in a specific line

查看:39
本文介绍了Inno Setup-如何在特定行中保存节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关inno设置的帮助,我需要在特定行中保存一些xml节点,但是我不知道该怎么做.

i need help with inno setup, i need to save some xml nodes in a specific line, but i dont know how to.

这是我的代码

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', mbError, MB_OK);
  end;
end;

function NextButtonClick(PageID: Integer): Boolean;
var
  XMLFile: string;
begin
  Result := True;
  if (PageId = wpFinished) then
  begin
    XMLFile := ExpandConstant('{pf}\Hell\0\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:HKCU\SOFTWARE\Craps,InstallPath}\Test.exe'));
    end;
  end;
end;

这是我的XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<stuffs>
        <stuff ident="555" path="C:\Program Files (x86)\Other thing\Other.exe" param="-alive" display="1" priority="0"/>
        <stuff ident="666" path="C:\Program Files (x86)\Craps\test.exe" param="-dead" display="1" priority="0"/>    
</stuffs>

问题是我的脚本总是写在第一行.我需要的是始终将节点保存在以<stuff ident="666"

The problem is that my script always write in the first line. What i need is to always save the nodes in the line that start with <stuff ident="666"

提前谢谢!

推荐答案

您将需要使用

You will need to use the setAttribute method insted of setting text property. Here is a procedure for modifying node attribute values:

procedure SaveAttributeValueToXML(const AFileName, APath, 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, mbError, 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, 
      mbError, MB_OK);  
  end;
end;

这是如何查询其ident参数值为666并且其param属性值将更改为-alive的节点的方法:

And here is how to query a node whose ident parameter value is 666 and whose param attribute value will be changed to -alive:

SaveAttributeValueToXML('d:\File.xml', '//stuffs/stuff[@ident=''666'']',
  'param', '-alive');

有关此处使用的XPath查询的更多信息,请参见到 this article .

For more information about the XPath query used here refer e.g. to this article.

这篇关于Inno Setup-如何在特定行中保存节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆