Einzelnen Beitrag anzeigen

Delphi-Lover

Registriert seit: 19. Okt 2004
Ort: Amsterdam
30 Beiträge
 
Delphi 2005 Professional
 
#4

Re: Saving Document XML Source from TWebbrowser

  Alt 10. Okt 2006, 14:17
Hello,

On the web I've searched and searched, but my question seems a difficult problem. I found on a newsgroup someone with a similar problem.

View Source for WebBrowser control from C# program

Only the final solution the poster adds to the group as an attachment I can not find.
(The page above points not to the original newsgroup but to one of these newsgroup-collectors-sites)

But maybe it helps to understand the problem better.


here is the working code as how shmia wanted to do it.
(It works, but not solve the problem...)

Delphi-Quellcode:
var FileStream: TFileStream;

    procedure InternalSaveDocumentToStream(const Stream: TStream);
    var
      StreamAdapter: IStream;
      PersistStreamInit: IPersistStreamInit;
    begin
      Assert(Assigned(webbrowser.Document));
      if webbrowser.Document.QueryInterface(IPersistStreamInit, PersistStreamInit) = S_OK then
      begin
        StreamAdapter := TStreamAdapter.Create(Stream);
        PersistStreamInit.Save(StreamAdapter, False);
      end;
    end;

FileStream := TFileStream.Create('Return.xml', fmCreate);
try
  InternalSaveDocumentToStream(FileStream);
finally
  FileStream.Free;
end;
and here is code how to display the View-Source textbox.
(With the real source of the page, but it's an execute of a notepad session and I'm not able to save it in the delphi code...)

Delphi-Quellcode:

    procedure WBViewSourceDialog(AWebBrowser: TWebbrowser) ;
    const
      CGID_WebBrowser: TGUID = '{ED016940-BD5B-11cf-BA4E-00C04FD70816}';
      HTMLID_VIEWSOURCE = 2;

    var
      CmdTarget : IOleCommandTarget;
      vaIn, vaOut: OleVariant;
      PtrGUID: PGUID;
    begin
      New(PtrGUID) ;
      PtrGUID^ := CGID_WebBrowser;
      if AWebBrowser.Document <> nil then
        try
          AWebBrowser.Document.QueryInterface(IOleCommandTarget, CmdTarget) ;
          if CmdTarget <> nil then
          try
            CmdTarget.Exec(PtrGUID, HTMLID_VIEWSOURCE, 0, vaIn, vaOut) ;
          finally
            CmdTarget._Release;
          end;
        except
       end;
      Dispose(PtrGUID) ;
    end;

Greets,

Delphi-Lover.
Rob
  Mit Zitat antworten Zitat