Solved

IHTMLDocument2

Posted on 2003-11-01
9
1,260 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 250 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 2

Accepted Solution

by:
gimmeadrink earned 250 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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