Inno Setup error in appendChild msxml

I want to change the xml file in Inno Setup, but the installation fails. I tried different things, and the result was a sample code with a problem

procedure testXml(); var xmlDocLocal, nodeLocal: Variant; begin try xmlDocLocal := CreateOleObject('MSXML2.DOMDocument'); xmlDocLocal.async := False; xmlDocLocal.resolveExternals := False; xmlDocLocal.loadXML('<root></root>'); nodeLocal := xmlDocLocal.CreateElement('element1'); xmlDocLocal.documentElement.appendChild(nodeLocal); except end; end; 

During the second call, the installer resets the appendChild method. What am I doing wrong?

+4
source share
1 answer

Three ideas: first, we use InnoSetup, but for us, OleObject needs to be created with a different line ending with a specific version 6.0:

 try XMLDoc := CreateOleObject('MSXML2.DOMDocument.6.0'); except RaiseException('Please install MSXML first.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)'); end; 

Second idea: try adding the xml header to the XML string contained in your code. Like this:

 xmlDocLocal.loadXML('<?xml version="1.0" encoding="UTF-8" ?><root></root>'); 

Third idea: try to check for errors (as I already showed in the first fragment). This may give you a pretty good idea of ​​what goes wrong. So we do it (and it works):

 XMLDoc.load(XMLFileName); if XMLDoc.parseError.errorCode <> 0 then XMLDoc.load(XMLFileName2); if XMLDoc.parseError.errorCode <> 0 then RaiseException('Error on line ' + IntToStr(XMLDoc.parseError.line) + ', position ' + IntToStr(XMLDoc.parseError.linepos) + ': ' + XMLDoc.parseError.reason); 

Hope this helps you. It is difficult to solve an unknown problem; -)

+1
source

Source: https://habr.com/ru/post/1494057/


All Articles