Exemple #1
0
        //procedure MSXMLButtonOnClick(Sender: TObject);
        //var
        //    XMLHTTP, XMLDoc, NewNode, RootNode: Variant;
        //    Path: String;
        //begin
        //    if MsgBox('Setup will now use MSXML to download XML file ''' + XMLURL + ''' and save it to disk.'#13#13'Setup will then load, modify and save this XML file. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
        //    Exit;

        //    { Create the main MSXML COM Automation object }

        //    try
        //    XMLHTTP := CreateOleObject('MSXML2.ServerXMLHTTP');
        //    except
        //    RaiseException('Please install MSXML first.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
        //    end;

        //    { Download the XML file }

        //    XMLHTTP.Open('GET', XMLURL, False);
        //    XMLHTTP.Send();

        //    Path := ExpandConstant('{src}\');
        //    XMLHTTP.responseXML.Save(Path + XMLFileName);

        //    MsgBox('Downloaded the XML file and saved it as ''' + XMLFileName + '''.', mbInformation, mb_Ok);

        //    { Load the XML File }

        //    XMLDoc := CreateOleObject('MSXML2.DOMDocument');
        //    XMLDoc.async := False;
        //    XMLDoc.resolveExternals := False;
        //    XMLDoc.load(Path + XMLFileName);
        //    if XMLDoc.parseError.errorCode<> 0 then
        //    RaiseException('Error on line ' + IntToStr(XMLDoc.parseError.line) + ', position ' + IntToStr(XMLDoc.parseError.linepos) + ': ' + XMLDoc.parseError.reason);

        //    MsgBox('Loaded the XML file.', mbInformation, mb_Ok);

        //    { Modify the XML document }

        //    NewNode := XMLDoc.createElement('isxdemo');
        //    RootNode := XMLDoc.documentElement;
        //    RootNode.appendChild(NewNode);
        //    RootNode.lastChild.text := 'Hello, World';

        //    { Save the XML document }

        //    XMLDoc.Save(Path + XMLFileName2);

        //    MsgBox('Saved the modified XML as ''' + XMLFileName2 + '''.', mbInformation, mb_Ok);
        //end;

        private void MSXMLButtonOnClick(TObject Sender)
        {
            if (MsgBox("Setup will now use MSXML to download XML file '" + XMLURL + "' and save it to disk.\r\rSetup will then load, modify and save this XML file. Do you want to continue?",
                       TMsgBoxType.Information,
                       MB.YesNo) == MsgBoxResult.No)
            {
                return;
            }

            dynamic XMLHTTP;

            // Create the main MSXML COM Automation object
            try
            {
                XMLHTTP = CreateOleObject("MSXML2.ServerXMLHTTP");
            }
            catch
            {
                throw new Exception("Please install MSXML first.\r\r(Error '" + GetExceptionMessage() + "' occurred)");
            }

            // Download the XML file
            XMLHTTP.Open("GET", XMLURL, false);
            XMLHTTP.Send();

            var Path = ExpandConstant("{src}\\");

            XMLHTTP.responseXML.Save(Path + XMLFileName);

            MsgBox("Downloaded the XML file and saved it as '" + XMLFileName + "'.", TMsgBoxType.Information, MB.Ok);

            // Load the XML File

            var XMLDoc = CreateOleObject("MSXML2.DOMDocument");

            XMLDoc.async            = false;
            XMLDoc.resolveExternals = false;
            XMLDoc.load(Path + XMLFileName);
            if (XMLDoc.parseError.errorCode != 0)
            {
                throw new Exception("Error on line " + IntToStr(XMLDoc.parseError.line) + ", position " + IntToStr(XMLDoc.parseError.linepos) + ": " + XMLDoc.parseError.reason);
            }

            MsgBox("Loaded the XML file.", TMsgBoxType.Information, MB.Ok);

            // Modify the XML document
            var NewNode  = XMLDoc.createElement("isxdemo");
            var RootNode = XMLDoc.documentElement;

            RootNode.appendChild(NewNode);
            RootNode.lastChild.text = "Hello, World";

            // Save the XML document
            XMLDoc.Save(Path + XMLFileName2);
            MsgBox("Saved the modified XML as '" + XMLFileName2 + "'.", TMsgBoxType.Information, MB.Ok);
        }