2013-03-30 2 views
2

inno 설치에 도움이 필요합니다. 특정 줄에 XML 노드를 저장해야하지만 어떻게해야할지 모르겠다.Inno Setup - 특정 줄에 노드를 저장하는 방법

<?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> 

문제는 내 스크립트가 항상 첫 번째 줄에 쓸 것입니다 :

내 코드

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 파일입니다. 내가 필요로하는 것은 항상 시작 라인에 노드를 저장하는 것입니다. <stuff ident="666"

미리 감사드립니다!

답변

4

text 속성을 설정하는 방법 setAttribute을 사용해야합니다. 여기에서 노드의 속성 값을 수정하는 방법이다

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 변경 될 노드를 조회하는 방법이다

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

를 들어 여기에 사용 된 XPath 쿼리에 대한 자세한 내용은 예를 들어 참조하십시오. this article.

+0

답변 해 주셔서 감사합니다. – Dielo

+1

당신을 환영합니다! – TLama

관련 문제