使用XMLNode到setAttribute时的Nil接口异常

时间:2014-05-14 09:59:54

标签: inno-setup msxml

我已经引用How to read and write XML document node values?编写代码来设置standalone-full.xml的属性。 这是代码。

procedure SaveAttributeToXML(const AFileName, APath, AAttribute, 
  AValue: string);
var
  XMLNode: Variant;
  XMLDocument: Variant;  
begin
  XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0');
  try
    XMLDocument.async := False;
    MsgBox(AFileName, mbConfirmation, MB_OK);
    MsgBox(APath, mbConfirmation, MB_OK);    
    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;
procedure CurStepChanged(CurStep: TSetupStep);
begin
  if(CurStep=ssPostInstall) then begin
   SaveAttributeToXML(ExpandConstant('{app}') + '\jboss\standalone\configuration\standalone-full.xml','/server/profile/subsystem[@xmlns=''urn:jboss:domain:web:1.1'']/connector[@name=''http'']','enabled',HttpEnable);
  end
end;

这是xml

<server xmlns="urn:jboss:domain:1.2">
...
<profile>
 <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
            <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" executor="http-executor" enabled="true"/>
            <connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" secure="true" executor="http-executor" enabled="true">
                <ssl name="ssl" password="changeit" certificate-key-file="${jboss.server.config.dir}/wfa.keystore" cipher-suite="TLS_RSA_WITH_AES_256_CBC_SHA,TLS_DHE_RSA_WITH_AES_256_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA" verify-client="false"/>
            </connector>
            <virtual-server name="default-host" enable-welcome-root="false">
                <alias name="localhost"/>
                <sso reauthenticate="true"/>
            </virtual-server>
        </subsystem>
<profile>
</server>

但是我得到了Nil接口异常。

0 个答案:

没有答案