Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you're approaching this the wrong way. A <code>TWebBrowser</code> control is a visual control intended for viewing. You may be able to extract the underlying data from it, but fundamentally, using visual control to download something (a non-visual action) is not a good approach. Instead, you should download the file using a dedicated API.</p> <blockquote> <p>Just for your information: There is no way for me to use WebClient or Indy components to access the xml. I also can't play as a Proxy since...</p> </blockquote> <p>Don't you have those components? In that case, I'd suggest you use either of the following approaches:</p> <ol> <li><p><a href="http://docwiki.embarcadero.com/VCL/en/ExtActns.TDownLoadURL" rel="nofollow"><code>TDownloadURL</code></a> is an inbuilt class, useful for simple downloading of a file. Some examples of using it:</p> <ul> <li><a href="http://delphi.about.com/od/networking/a/html_scraping.htm" rel="nofollow">An HTML page scraper</a> - obviously also applicable to XML</li> <li><a href="http://delphi.about.com/cs/adptips2003/a/bltip0903_2.htm" rel="nofollow">How to show a progress indicator while downloading</a> - may not be useful if your file is small</li> </ul></li> <li><p><a href="http://msdn.microsoft.com/en-us/library/aa385103%28v=vs.85%29.aspx" rel="nofollow">InternetReadFile</a>. This is what I personally use in my own code - I have a small thread class to asynchronously download files and notify the main thread when they're done, implemented using this function. Use it by:</p> <ul> <li>Use <a href="http://msdn.microsoft.com/en-us/library/aa385096%28v=vs.85%29.aspx" rel="nofollow">InternetOpen</a> to initialise use of the internet functions; it returns a handle;</li> <li>Use that handle to get another handle using <a href="http://msdn.microsoft.com/en-us/library/aa385098%28v=vs.85%29.aspx" rel="nofollow">InternetOpenUrl</a> using the <code>INTERNET_FLAG_HYPERLINK or INTERNET_FLAG_NO_UI</code> flags</li> <li>Then use that handle with <a href="http://msdn.microsoft.com/en-us/library/aa385103%28v=vs.85%29.aspx" rel="nofollow">InternetReadFile</a> in a loop writing to a buffer until the file is read or your thread is terminated.</li> <li>Don't forget to close the handles using <a href="http://msdn.microsoft.com/en-us/library/aa384350%28v=vs.85%29.aspx" rel="nofollow">InternetCloseHandle</a> </li> </ul> <p>Sorry I can't post source code, but they're simple functions and you should find it easy enough to write.</p></li> </ol> <p>These approaches will get your either a file or a buffer, each containing the raw contents of your XML file.</p> <p><strong>Edit:</strong> I see you explained a bit about why you can't use Indy: </p> <blockquote> <p>"The real scenario is much complex and need user interaction in the browser and after the user did everything there are some post posts between browser and user till the end result is a XML file which you have no control on where is comes from!"</p> </blockquote> <p>I'm not certain this stops you using Indy: instead you just need to get the location of this XML. The fact you don't control where it is doesn't matter, you just need to find out where it is. Either scrape the HTML if all you have is a link (you can already get HTML from the browser - in fact, that's your problem!) or look at the final location the <code>TWebBrowser</code> document is located at, and download that. In other words, let the user do whatever they have to do to navigate to the final XML file, but rather than trying to extract it from the web browser control, download it yourself.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload