Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用TWebBrowser Delphi组件下载XML文件_Delphi_Webbrowser Control - Fatal编程技术网

使用TWebBrowser Delphi组件下载XML文件

使用TWebBrowser Delphi组件下载XML文件,delphi,webbrowser-control,Delphi,Webbrowser Control,我不知道如何使用Delphi从TWebBrowser ActiveX组件检索XML内容 如果结果是HTML,我可以使用: iall := (WebBrowser1.Document AS IHTMLDocument2).body; while iall.parentElement <> nil do begin iall := iall.parentElement; end; memo1.Text := iall.outerHTML; 备注:我无法使用Indy HT

我不知道如何使用Delphi从TWebBrowser ActiveX组件检索XML内容

如果结果是HTML,我可以使用:

 iall := (WebBrowser1.Document AS IHTMLDocument2).body;
 while iall.parentElement <> nil do
 begin
   iall := iall.parentElement;
 end;
 memo1.Text := iall.outerHTML;

备注:我无法使用Indy HTTPClient组件,因为该程序将在不同的代理配置上运行,并且很难处理许多配置。

这似乎适用于本地XML文件,也适用于URL:

procedure TForm3.FormShow(Sender: TObject);
begin
  WebBrowser1.Navigate('file:///d:/temp/TestFile.xml');
end;

procedure TForm3.WebBrowser1DocumentComplete(ASender: TObject;
  const pDisp: IDispatch; const URL: OleVariant);
var
  HTML: IHtmlDocument2;
  XMLText: String;
begin
  HTML := WebBrowser1.Document as IHTMLDocument2;
  XMLText := HTML.body.outerText;

  // Just for display purposes, obviously. 
  ShowMessage(XMLText);
end;

这似乎适用于本地XML文件,也适用于URL:

procedure TForm3.FormShow(Sender: TObject);
begin
  WebBrowser1.Navigate('file:///d:/temp/TestFile.xml');
end;

procedure TForm3.WebBrowser1DocumentComplete(ASender: TObject;
  const pDisp: IDispatch; const URL: OleVariant);
var
  HTML: IHtmlDocument2;
  XMLText: String;
begin
  HTML := WebBrowser1.Document as IHTMLDocument2;
  XMLText := HTML.body.outerText;

  // Just for display purposes, obviously. 
  ShowMessage(XMLText);
end;

使用IE控件来完成这样的任务真是太过分了。Windows WinINet API使用OS/IE中定义的代理设置。因此,您可以使用URLDownloadToFile:URLDownloadToFilenil,'file.xml',0,nil;您好,Antonio,服务器上没有file.xml。是一个以友好方式组装XML的请求。此外,我找不到URLDownloadToFile的单位。下面是一个例子,不管服务器返回什么,URLDownloadToFile只会存储到文件使用IE控件执行此类任务确实是一种过度使用。Windows WinINet API使用OS/IE中定义的代理设置。因此,您可以使用URLDownloadToFile:URLDownloadToFilenil,'file.xml',0,nil;您好,Antonio,服务器上没有file.xml。是一个以友好方式组装XML的请求。此外,我找不到URLDownloadToFile的单位。下面是一个示例,不管服务器返回什么,URLDownloadToFile都会将其存储到文件中