2

I'm trying to add a few "variable" childs to a "variables" node in a dozen xml files.

This is what the XML files look like :

<?xml version="1.0" encoding="UTF-8"?>
<agent-input>
    <variables>
    </variables>
    <server>...

Here is my inno setup code :

procedure AddVariablesToXML(const AFileName: String);
var
  XMLNode, XMLDocument, XMLNodeVariable: Variant; 

begin
  XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0');
  try
    XMLDocument.async := False;
    XMLDocument.resolveExternals := False;
    XMLDocument.load(AFileName);
    if (XMLDocument.parseError.errorCode <> 0) then
      MsgBox('Erreur au parsing du fichier XML : ' + AFileName + 
        XMLDocument.parseError.reason, mbError, MB_OK)
        //TODO GestionErreur
    else
    begin
      XMLDocument.setProperty('SelectionLanguage', 'XPath');
      XMLDocument.selectNodes('//agent-input//variables//variable').removeAll();

      LOG(AFileName);
      LOG('1');

      XMLNode := XMLDocument.selectSingleNode('//agent-input//variables');

      LOG('2');

      XMLNodeVariable := XMLDocument.createElement('variable');
      XMLNodeVariable.setAttribute('name', 'Computer');
      XMLNodeVariable.setAttribute('value', 'TEST');
      XMLNode.appendChild(XMLNodeVariable);

      LOG('3');

      XMLNodeVariable := XMLDocument.createElement('variable');
      XMLNodeVariable.setAttribute('name', 'DomaineDNS');
      XMLNodeVariable.setAttribute('value', 'TEST');
      XMLNode.appendChild(XMLNodeVariable);  

      LOG('4');

      XMLDocument.save(AFileName);
    end;

  except
    MsgBox('An error occured! \line' + GetExceptionMessage, mbError, MB_OK);
    //TODO GestionErreur
  end;
end;

This works fine on the first 2 files but crashes on the 3rd one after the LOG 2; I've tried changing the 3rd file to one that works to see if something in that file is responsible but it crashes at the exact same spot...

All I have is a Setup exit code: 255.

My problem doesn't seem to be like those 2 I've found on SO :

Inno Setup crashes in appendChild msxml

Adding nodes to xml with DOM in inno Setup - strange problems

Community
  • 1
  • 1
Celeste
  • 21
  • 4
  • Some notes on the MSXML crashes, which may be relevant. http://stackoverflow.com/a/42869405/572002 – Nicholi Mar 18 '17 at 01:24

0 Answers0