?
Solved

IHTMLDocument2

Posted on 2003-11-01
9
Medium Priority
?
1,324 Views
Last Modified: 2013-12-03
Hi

I have written an IE BHO that uses the IHTMLDocument2 interface to alter the HTML, i need to be able to get the complete modified source including all the tags <!DOCTYPE....<HTML>....</HTML>. the get_body->get_innerHTML only gives me the <BODY>.....</BODY> section, thats no good i need the lot.

I either need to have it as a sting (BSTR) or be able to save it to a file.

i have already seen the few questions on here that suggest get_body, please dont suggest them... it dont work how i want it to.

Ta

Paul
0
Comment
Question by:makerp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 6

Expert Comment

by:purpleblob
ID: 9663158
I've done this in C# but using IHTMLDocument3 object - however the following C++ should work

QI your IHTMLDocument2 to get an IHTMLDocument3 interface (hopefully) you'll get an IHTMLDocument3 interface back and from this you should be able to get what you want.

Here's the source (note: it's in the most basic form, i.e. no ATL etc. and for brevity all error handling has been removed).

IHTMLDocument3 pHTMLDoc3;
pHTMLDoc2->QueryInterface(IID_IHTMLDocument3, reinterpret_cast<void**>(&pHTMLDoc3);

IHTMLElement* pDocElem;
pHTMLDoc3->get_DocumentElement(&pDocElem);

pHTMLDoc3->Release();

BSTR bstrHTML;
pDocElem->get_OuterHTML(&bstrHTML);
pDocElem->Release();

I've not tested this C++ code but converted it to C# (as I've been using the browser recently in C#) and it seems to produce everything <html> to </html>.

0
 
LVL 8

Expert Comment

by:_corey_
ID: 9663996
I'm pretty sure that'll work for IHTMLDocument2 ?
0
 
LVL 6

Assisted Solution

by:purpleblob
purpleblob earned 1000 total points
ID: 9664252
IHTMLDocument2 doesn't include the get_DocumentElement method. However there's another interface called HTMLDocument which also supports this method and can be used in place of IHTMLDocument3.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 2

Accepted Solution

by:
gimmeadrink earned 1000 total points
ID: 9709384
What about this...

HRESULT IHTMLDocument2::get_all(IHTMLElementCollection **p);

Its a zero based collection of all the elements in a webpage.
(see http://msdn.microsoft.com/workshop/author/dhtml/reference/collections/all.asp for more info)


the other option is 'tostring'  (http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/document2/tostring.asp)

I have used both of these (although a while ago) in visual basic, should act the same way for VC++ or whatever you are using.

HTH

0
 
LVL 8

Expert Comment

by:_corey_
ID: 9716457
ToString actually does that?  I voiced a thought about that in an earlier question but never actually tried it.
0
 
LVL 2

Expert Comment

by:gimmeadrink
ID: 9719327
hmmm, i might double-check..... it was a while ago that i used it ;)

I'll get back to ya.
0
 
LVL 10

Author Comment

by:makerp
ID: 9733611
i have solved this by getting the IPersistFile interface from the IHTMLDocument2 object...

thanx anyway
0
 
LVL 10

Author Comment

by:makerp
ID: 10800469
sorry about the delay - since the update of the look & feel of EE the flash, adverts and animated gifs anoy slightly.

none of the solutions proposed here are really suitable because of the way IE alters the raw HTML in its object model. anyway i will split the points.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question