Solved

I have a CComPtr<IWebBrowser2> m_pWB2, how can I enumerate all the document elements?

Posted on 2009-07-02
2
551 Views
Last Modified: 2013-12-04
In my DOWNLOADCOMPLETE event I want to enumerate all ATML tags, and, say, see their InnerHTML content.

How do I get this done starting with my IWebBrowser2 * ?
0
Comment
Question by:yossikally
[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 Comments
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 24767025
The thread at http://www.experts-exchange.com/Programming/Languages/CPP/Q_20194736.html provides a sample that might be exactly what you are looking for.

Looking at the description of the DownloadComplete http://msdn.microsoft.com/en-us/library/aa768331%28VS.85%29.aspx event it states that it fires when a navigation operation finishes, is halted, or fails which might give you trouble when you try to traverse the document especially if the latter two cases occur. Perhaps NavigateComplete or NavigateComplete2 might be better events.
0
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 500 total points
ID: 24768614
...here is also an example based on the code referenced in the first post:
void YourCHtmlViewDerivedClass::OnNavigateComplete2(LPCTSTR strURL)
{
	CComPtr<IDispatch> spDisp = CHtmlView::GetHtmlDocument();
	IHTMLDocument2 * pHTML = NULL;
	IHTMLElementCollection * pElement = NULL;
	VARIANT vtName, vtIndex;
	BSTR bstrVal;
	CString sInnerHTML;
 
	spDisp->QueryInterface(IID_IHTMLDocument2, (LPVOID *) &pHTML);
	
	pHTML->get_all(&pElement);
 
	LONG nItems = 0;
        pElement->get_length(&nItems);
 
	for(int i = 0; i < nItems; i++) {
		vtName.vt = VT_I4;
		vtName.lVal = i;
		vtIndex.lVal = 1;
		vtIndex.vt = VT_I4;
 
		CComPtr<IDispatch> spDispTemp;
		pElement->item(vtName, vtIndex, &spDispTemp);
 
		IHTMLElement * pItem = NULL;
 
		spDispTemp->QueryInterface(IID_IHTMLElement, (LPVOID*)&pItem);
 
		if(pItem == NULL) {
			AfxMessageBox(_T("pItem is NULL"));
			return;
		}
 
		pItem->get_innerHTML(&bstrVal);
 
		sInnerHTML = bstrVal;
 
		AfxMessageBox(sInnerHTML);
	}
}

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
post4 challenge 28 113
x-bar in Google Sheets 2 98
Way to decrease size of apk file 9 112
Capture logon name 13 106
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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…

696 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