How to get XML (RAW/SOURCE) from a WebBrowser Control

前端 未结 2 498
旧巷少年郎
旧巷少年郎 2021-02-08 16:28

I am using the WebBrowser Control in my both Delphi and .Net C# test projects to navigate to a local test XML file and try to save the content back to a XML file in .Net D

2条回答
  •  青春惊慌失措
    2021-02-08 17:06

    You could do a "shadow" download of the file in the TWebBrowser BeforeNavigate2 event.
    By shadow, I mean use a procedure from another library to download the file at the same time TWebBrowser is downloading it. This way, you can get the file without it being modified by TWebBrowser.

    I wrote a test application and all I had to do the get the file contents is

    procedure TForm1.WebBrowserBeforeNavigate2(Sender: TObject;
      const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
      Headers: OleVariant; var Cancel: WordBool);
    begin
      HttpGetText(URL,Memo1.Lines);
    end;
    

    The HttpGetText is a blocking function from the Synapse library http://www.ararat.cz/synapse/doku.php/start

    You could also use ICS, Indy, or TDownLoadURL. Note, TDownLoadURL is not blocking and I was never able to get its AfterDownload event to work.

提交回复
热议问题