Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get XML (RAW/SOURCE) from a WebBrowser Control
    primarykey
    data
    text
    <p>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 <code>DocumentCompleted</code> Event and in Delphi <code>onNavigateComple2</code> event.</p> <p>The Problem is that I always get HTML which will be transformed by Browser for viewing (check my output: I saved that with using the following code)</p> <pre><code>procedure TForm1.SaveHTMLSourceToFile(const FileName: string; WB: TWebBrowser); var PersistStream: IPersistStreamInit; FileStream: TFileStream; Stream: IStream; SaveResult: HRESULT; begin PersistStream := WB.Document as IPersistStreamInit; FileStream := TFileStream.Create(FileName, fmCreate); try Stream := TStreamAdapter.Create(FileStream, soReference) as IStream; SaveResult := PersistStream.Save(Stream, True); if FAILED(SaveResult) then MessageBox(Handle, 'Fail to save source', 'Error', 0); finally FileStream.Free; end; end; </code></pre> <p>Well, I've tried almost everything, searched everywhere but till now couldn't find anyhting useful. With the following Delphi Code I manged to show the SOURCE which works (That means the source is somewhere there) but I can not use this since it will sow a dialog and not easy to get the data and close that dialog (in my test case I get the notepad.exe with my xml content)</p> <pre><code> AWebBrowser.Document.QueryInterface(IOleCommandTarget, CmdTarget) ; if CmdTarget &lt;&gt; nil then try CmdTarget.Exec(PtrGUID, HTMLID_VIEWSOURCE, 0, vaIn, vaOut) ; finally CmdTarget._Release; end; </code></pre> <p>I also managed to call the SAVE AS call with the xxx-HIDE-xxx Flag, but it seams up IE 5 the save as Dialog will be shown (the hide flag will be ignored).</p> <p>I also tried to get the XML Data from Cache (Cache API) but in my case I won't get anything and 2. what if on customer machine the caching is disabled? ;-)</p> <p>InnerText or InnerHTML atc. can not be used, since they contain - and + char and not representing the orignial RAW data (the SOURCE)</p> <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 the Problem with the opening the ports (let say 8080) on customers machine is painful with privileged user access.</p> <p>So here I am and asking you if you have any idea how to solve my Problem?</p> <p>Thanks in advance, Cheers</p> <p>input:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;test&gt;&lt;data&gt;xxxx&lt;/data&gt;&lt;/test&gt; </code></pre> <p>output:</p> <pre><code>&lt;HTML&gt;&lt;HEAD&gt; &lt;STYLE&gt;BODY{font:x-small 'Verdana';margin-right:1.5em} .c{cursor:hand} .b{color:red;font-family:'Courier New';font-weight:bold;text-decoration:none} .e{margin-left:1em;text-indent:-1em;margin-right:1em} .k{margin-left:1em;text-indent:-1em;margin-right:1em} .t{color:#990000} .xt{color:#990099} .ns{color:red} .dt{color:green} .m{color:blue} .tx{font-weight:bold} .db{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;border-left:1px solid #CCCCCC;font:small Courier} .di{font:small Courier} .d{color:blue} .pi{color:blue} .cb{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;font:small Courier;color:#888888} .ci{font:small Courier;color:#888888} PRE{margin:0px;display:inline}&lt;/STYLE&gt; &lt;SCRIPT&gt;&lt;!-- function f(e){ if (e.className=="ci"){if (e.children(0).innerText.indexOf("\n")&gt;0) fix(e,"cb");} if (e.className=="di"){if (e.children(0).innerText.indexOf("\n")&gt;0) fix(e,"db");} e.id=""; } function fix(e,cl){ e.className=cl; e.style.display="block"; j=e.parentElement.children(0); j.className="c"; k=j.children(0); k.style.visibility="visible"; k.href="#"; } function ch(e){ mark=e.children(0).children(0); if (mark.innerText=="+"){ mark.innerText="-"; for (var i=1;i&lt;e.children.length;i++) e.children(i).style.display="block"; } else if (mark.innerText=="-"){ mark.innerText="+"; for (var i=1;i&lt;e.children.length;i++) e.children(i).style.display="none"; }} function ch2(e){ mark=e.children(0).children(0); contents=e.children(1); if (mark.innerText=="+"){ mark.innerText="-"; if (contents.className=="db"||contents.className=="cb") contents.style.display="block"; else contents.style.display="inline"; } else if (mark.innerText=="-"){ mark.innerText="+"; contents.style.display="none"; }} function cl(){ e=window.event.srcElement; if (e.className!="c"){e=e.parentElement;if (e.className!="c"){return;}} e=e.parentElement; if (e.className=="e") ch(e); if (e.className=="k") ch2(e); } function ex(){} function h(){window.status=" ";} document.onclick=cl; --&gt;&lt;/SCRIPT&gt; &lt;/HEAD&gt; &lt;BODY class="st"&gt;&lt;DIV class="e"&gt; &lt;SPAN class="b"&gt;&amp;nbsp;&lt;/SPAN&gt; &lt;SPAN class="m"&gt;&amp;lt;?&lt;/SPAN&gt;&lt;SPAN class="pi"&gt;xml version="1.0" encoding="UTF-8" &lt;/SPAN&gt;&lt;SPAN class="m"&gt;?&amp;gt;&lt;/SPAN&gt; &lt;/DIV&gt; &lt;DIV class="e"&gt; &lt;DIV class="c" STYLE="margin-left:1em;text-indent:-2em"&gt;&lt;A href="#" onclick="return false" onfocus="h()" class="b"&gt;-&lt;/A&gt; &lt;SPAN class="m"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class="t"&gt;test&lt;/SPAN&gt;&lt;SPAN class="m"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt; &lt;DIV&gt;&lt;DIV class="e"&gt;&lt;DIV STYLE="margin-left:1em;text-indent:-2em"&gt; &lt;SPAN class="b"&gt;&amp;nbsp;&lt;/SPAN&gt; &lt;SPAN class="m"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class="t"&gt;data&lt;/SPAN&gt;&lt;SPAN class="m"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="tx"&gt;xxxx&lt;/SPAN&gt;&lt;SPAN class="m"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class="t"&gt;data&lt;/SPAN&gt;&lt;SPAN class="m"&gt;&amp;gt;&lt;/SPAN&gt; &lt;/DIV&gt;&lt;/DIV&gt; &lt;DIV&gt;&lt;SPAN class="b"&gt;&amp;nbsp;&lt;/SPAN&gt; &lt;SPAN class="m"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class="t"&gt;test&lt;/SPAN&gt;&lt;SPAN class="m"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt; &lt;/DIV&gt;&lt;/DIV&gt; &lt;/BODY&gt; &lt;/HTML&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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