Click here to Skip to main content
15,896,153 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: text nodes Pin
llp00na2-Mar-06 23:30
llp00na2-Mar-06 23:30 
GeneralRe: text nodes Pin
Stephen Hewitt3-Mar-06 0:42
Stephen Hewitt3-Mar-06 0:42 
GeneralRe: text nodes Pin
llp00na3-Mar-06 4:09
llp00na3-Mar-06 4:09 
GeneralRe: text nodes Pin
Stephen Hewitt3-Mar-06 19:18
Stephen Hewitt3-Mar-06 19:18 
GeneralRe: text nodes Pin
llp00na4-Mar-06 5:41
llp00na4-Mar-06 5:41 
GeneralRe: text nodes Pin
Stephen Hewitt4-Mar-06 15:00
Stephen Hewitt4-Mar-06 15:00 
GeneralRe: text nodes Pin
llp00na5-Mar-06 1:38
llp00na5-Mar-06 1:38 
GeneralRe: text nodes Pin
Stephen Hewitt4-Mar-06 15:56
Stephen Hewitt4-Mar-06 15:56 
Here's some code which doesn't do what you want, but contains all the elements you need. You should be able to alter it to suit your needs. It uses straight COM without any smart pointers. Normally I'd use ATL smart pointers but I thought this way it will work "out of the box", you can alter it use your favorite smart pointers. The code will be considerably smaller if you alter it to use some kind of smart pointer. Here goes:
-------------
void CMFCWebBrowserDlg::OnButton1()
{
IDispatch *pDisp = m_Browser.GetDocument();
if ( pDisp != NULL )
{
IHTMLDocument2 *pDoc2;
HRESULT hr = pDisp->QueryInterface(&pDoc2);
if ( SUCCEEDED(hr) )
{
ASSERT(pDoc2);

IHTMLElement *pBodyElement;
hr = pDoc2->get_body(&pBodyElement);
if ( SUCCEEDED(hr) && pBodyElement )
{
IHTMLDOMNode *pDOMNode;
hr = pBodyElement->QueryInterface(&pDOMNode);
if ( SUCCEEDED(hr) )
{
ASSERT(pDOMNode);

IDispatch *pChildrenDisp;
hr = pDOMNode->get_childNodes(&pChildrenDisp);
if ( SUCCEEDED(hr) )
{
ASSERT(pChildrenDisp);

IHTMLDOMChildrenCollection *pChildrenCollection;
hr = pChildrenDisp->QueryInterface(&pChildrenCollection);
if ( SUCCEEDED(hr) )
{
ASSERT(pChildrenCollection);

long NumItems;
if ( SUCCEEDED(pChildrenCollection->get_length(&NumItems)) )
{
for ( long i=0; i<NumItems; ++i )
{
IDispatch *pItemDisp;
hr = pChildrenCollection->item(i, &pItemDisp);
if ( SUCCEEDED(hr) && pItemDisp!=NULL )
{
// Is it a text node?
IHTMLDOMTextNode *pTextNode;
hr = pItemDisp->QueryInterface(&pTextNode);
if ( SUCCEEDED(hr) )
{
// It's a text node so get the text.
BSTR bstrText;
hr = pTextNode->get_data(&bstrText);
if ( SUCCEEDED(hr) )
{
MessageBoxW(m_hWnd, bstrText, L"Text node", MB_OK);

SysFreeString(bstrText);
}
}
else
{
// It's not a text node.
IHTMLElement *pElem;
hr = pItemDisp->QueryInterface(&pElem);
if ( SUCCEEDED(hr) )
{
ASSERT(pElem);

BSTR bstrOuter;
hr = pElem->get_outerHTML(&bstrOuter);
if ( SUCCEEDED(hr) )
{
MessageBoxW(m_hWnd, bstrOuter, L"Element", MB_OK);

SysFreeString(bstrOuter);
}

pElem->Release();
}
}

pItemDisp->Release();
}
}
}

pChildrenCollection->Release();
}

pChildrenDisp->Release();
}

pDOMNode->Release();
}

pBodyElement->Release();
}

pDoc2->Release();
}

pDisp->Release();
}
}

Steve
GeneralRe: text nodes Pin
llp00na5-Mar-06 6:28
llp00na5-Mar-06 6:28 
Questioncgi mailer ---- giving troubles Pin
deepak11-Mar-06 12:12
deepak11-Mar-06 12:12 
AnswerRe: cgi mailer ---- giving troubles Pin
Vasudevan Deepak Kumar2-Mar-06 19:31
Vasudevan Deepak Kumar2-Mar-06 19:31 
GeneralRe: cgi mailer ---- giving troubles Pin
deepak15-Mar-06 9:06
deepak15-Mar-06 9:06 
QuestionGetting a list of links in an html file Pin
imadoki1-Mar-06 9:09
imadoki1-Mar-06 9:09 
AnswerRe: Getting a list of links in an html file Pin
Vasudevan Deepak Kumar1-Mar-06 22:57
Vasudevan Deepak Kumar1-Mar-06 22:57 
QuestionNeed javascript code!!Urgent Pin
Sushant_Mathur1-Mar-06 4:16
Sushant_Mathur1-Mar-06 4:16 
QuestionRe: Need javascript code!!Urgent Pin
nicko1-Mar-06 14:35
nicko1-Mar-06 14:35 
AnswerRe: Need javascript code!!Urgent Pin
Vasudevan Deepak Kumar1-Mar-06 22:56
Vasudevan Deepak Kumar1-Mar-06 22:56 
QuestionHow to implement transactions in Biz logic layer in 3 tier arch. Pin
Ravi_Vaswani28-Feb-06 22:30
Ravi_Vaswani28-Feb-06 22:30 
AnswerRe: How to implement transactions in Biz logic layer in 3 tier arch. Pin
darkelv1-Mar-06 3:49
darkelv1-Mar-06 3:49 
AnswerRe: How to implement transactions in Biz logic layer in 3 tier arch. Pin
JP_Rocks9-May-11 0:28
JP_Rocks9-May-11 0:28 
Questionsort image list Pin
Marc Soleda28-Feb-06 20:05
Marc Soleda28-Feb-06 20:05 
AnswerRe: sort image list Pin
Vasudevan Deepak Kumar2-Mar-06 19:57
Vasudevan Deepak Kumar2-Mar-06 19:57 
GeneralRe: sort image list Pin
Marc Soleda2-Mar-06 20:08
Marc Soleda2-Mar-06 20:08 
QuestionAccessing Multiple form. ASP Pin
panalprasad28-Feb-06 17:28
panalprasad28-Feb-06 17:28 
AnswerRe: Accessing Multiple form. ASP Pin
Vasudevan Deepak Kumar1-Mar-06 22:58
Vasudevan Deepak Kumar1-Mar-06 22:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.