Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating .config XML in InstallScript
    primarykey
    data
    text
    <p>I am attempting to write a short install script to update a value in an XML file (myplatforinfo.config).</p> <p>I shamefully stole the code from [this post on a similar task]{http://stackoverflow.com/questions/4129633/how-to-update-attributes-in-an-xml-file-with-installscript}, but have hacked it for my needs.</p> <pre><code>/// &lt;summary&gt; /// This function reads in the fddId.config and alters the number associated /// with the serial number fo the installed package. /// &lt;summary&gt; function UpdateDeviceFirmwareVersion(hMSI) OBJECT oDoc; STRING sConfigFilePath; BOOL successfulLoad; NUMBER retVal; begin sConfigFilePath = "C:\\myplatforinfo.config"; retVal = 0; if (Is(FILE_EXISTS, sConfigFilePath)) = FALSE then MessageBox("Could not find fddId file.", 0); retVal = -1; endif; // get values from public properties set oDoc = CreateObject("Msxml2.DOMDocument.4.0"); if (!IsObject(oDoc)) then MessageBox("Could not create XML Document", 0); retVal = -1; endif; oDoc.async = FALSE; oDoc.setProperty("SelectionLanguage", "XPath"); successfulLoad = oDoc.load(sConfigFilePath); if (successfulLoad &lt; 0) then MessageBox("Could not load the fddId as an xml file", SEVERE); retVal = -1; endif; if (retVal = -1) then return retVal; abort; endif; ReplaceValueOf(oDoc, "//platformID/SerialNumber/version", "1"); oDoc.save(sConfigFilePath); set oDoc = NOTHING; end; function ReplaceValueOf(oDoc, xPath, valueToPutIn) OBJECT oNode; begin set oNode = oDoc.selectNodes(xPath)(0); try oNode.attributes.getNamedItem("value").value = valueToPutIn; catch MessageBox("Could not set '" + xPath + "' with '" + valueToPutIn + "'", SEVERE); endcatch; end; </code></pre> <p>It is however falling over on the load method, need help!:</p> <pre><code>successfulLoad = oDoc.load(sConfigFilePath); if (successfulLoad &lt; 0) then MessageBox("Could not load the fddId as an xml file", SEVERE); retVal = -1; endif; </code></pre> <p>I am not sure why. This file is a valid XML file and it handled ok by the .Net code that uses it. Below I have included a simplified version of the XML config file. Just the header and the tags that are used, but the structure is identical. It has comments in it, could this effect the InstallShield parser?</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;platformIDxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;type&gt;35&lt;/type&gt; &lt;manufacturer&gt;14&lt;/manufacturer&gt; &lt;SerialNumber&gt; &lt;version&gt;2&lt;/version&gt; &lt;/SerialNumber&gt; &lt;/platformID&gt; </code></pre> <p>I have only been battling with InstallShield 2011 for a short time, but I am fast learning to love it's power and hate it's development support and lack of a clear UI. Any help welcome :) .</p> <p>EDIT: As Michael Urman has kindly pointed out I wasn't correctly handling the boolean return from my XML Document load. I have made this edit and my script is now getting as far as the 'getNamedItem' and set the value. </p> <p>Is this possibly because the field I wish to set is not the named "value" attribute? My elements don't have any attributes, but I suspected the value for the element was an attribute named 'value', lol. Have I presumed wrong?</p> <p>Further EDIT!! Nope it's not the above then... I have tried the node.Value and the named element route, both ways the debugger crashes on the 'setter' line for the new value. Think I might just have to use the inbuilt function.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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