Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use the <a href="http://www.jrsoftware.org/ishelp/topic_isxfunc_createoleobject.htm"><code>CreateOleObject</code></a> function to instantiate the standard <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms756987%28v=vs.85%29.aspx"><code>MSXML2.DOMDocument</code></a> COM object. The following script shows how to load and save a text value for a single node from the XML file posted below (the script itself was inspired by the examples from MSDN):</p> <pre><code>[Setup] AppName=My Program AppVersion=1.5 DefaultDirName={pf}\My Program DefaultGroupName=My Program UninstallDisplayIcon={app}\MyProg.exe Compression=lzma2 SolidCompression=yes OutputDir=userdocs:Inno Setup Examples Output [Files] Source: "MyProg.exe"; DestDir: "{app}" Source: "MyProg.chm"; DestDir: "{app}" [Icons] Name: "{group}\My Program"; Filename: "{app}\MyProg.exe" [Code] var CustomEdit: TEdit; CustomPageID: Integer; function LoadValueFromXML(const AFileName, APath: string): string; var XMLNode: Variant; XMLDocument: Variant; begin Result := ''; XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDocument.async := False; XMLDocument.load(AFileName); if (XMLDocument.parseError.errorCode &lt;&gt; 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 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 &lt;&gt; 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.text := AValue; XMLDocument.save(AFileName); end; except MsgBox('An error occured!' + #13#10 + GetExceptionMessage, mbError, MB_OK); end; end; procedure InitializeWizard; var CustomPage: TWizardPage; begin CustomPage := CreateCustomPage(wpWelcome, 'Custom Page', 'Enter the new value that will be saved into the XML file'); CustomPageID := CustomPage.ID; CustomEdit := TEdit.Create(WizardForm); CustomEdit.Parent := CustomPage.Surface; end; procedure CurPageChanged(CurPageID: Integer); begin if CurPageID = CustomPageID then CustomEdit.Text := LoadValueFromXML('C:\Setup.xml', '//Setup/FirstNode'); end; function NextButtonClick(CurPageID: Integer): Boolean; begin Result := True; if CurPageID = CustomPageID then SaveValueToXML('C:\Setup.xml', '//Setup/FirstNode', CustomEdit.Text); end; </code></pre> <p>Here is the XML file used in the script:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Setup&gt; &lt;FirstNode&gt;First node value!&lt;/FirstNode&gt; &lt;SecondNode&gt;Second node value!&lt;/SecondNode&gt; &lt;/Setup&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload