EDN Admin
Well-known member
hi,all, I have the following two functions:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; void CHTMLBrowserDlg:rocessHTMLDoc(MSHTML::IHTMLDocument2Ptr pDoc)
{
MSHTML::IHTMLElementPtr pElemBody;
HRESULT hr;
hr = pDoc->get_body(&pElemBody);
<span style="color:Blue; if (SUCCEEDED(hr))
{
<span style="color:Green; // Obtained html body element.
ProcessElem(pElemBody);
pElemBody->Release();
}
}
<span style="color:Blue; void CHTMLBrowserDlg:rocessElem(MSHTML::IHTMLElementPtr pElem)
{
HRESULT hr;
<span style="color:Blue; long lLength = 0;
IDispatchPtr pElemDisp = NULL;
MSHTML::IHTMLElementCollectionPtr pChElemColl = NULL;
hr = pElem->get_children(&pElemDisp);
<span style="color:Blue; if(SUCCEEDED(hr))
{
hr = pElemDisp->QueryInterface(IID_IHTMLElementCollection, (VOID**)&pChElemColl);
<span style="color:Blue; if(SUCCEEDED(hr))
{
hr = pChElemColl->get_length(&lLength);
<span style="color:Blue; if(SUCCEEDED(hr))
{
<span style="color:Blue; for(<span style="color:Blue; int i = 0; i < lLength; i++)
{
VARIANT varIndex;
varIndex.vt = VT_UINT;
varIndex.lVal = i;
VARIANT var2;
VariantInit(&var2);
IDispatchPtr pDisp = NULL;
hr = pChElemColl->raw_item(varIndex, var2, &pDisp);
<span style="color:Blue; if(hr == S_OK)
{
MSHTML::IHTMLElementPtr pChElem = NULL;
hr = pDisp->QueryInterface(IID_IHTMLElement, (<span style="color:Blue; void **)&pChElem);
<span style="color:Blue; if(hr == S_OK)
{
CComBSTR bstr;
IDispatchPtr pDispCh = NULL;
<span style="color:Blue; long lChLength = 0;
MSHTML::IHTMLElementCollectionPtr pChColl = NULL;
hr = pChElem->get_tagName(&bstr);
CString strTag = bstr;
MSHTML::IHTMLImgElementPtr pImgElem;
hr = pDisp->QueryInterface(IID_IHTMLImgElement, (<span style="color:Blue; void **)&pImgElem);
<span style="color:Blue; if(hr == S_OK)
{
pImgElem->get_href(&bstr);
strTag += <span style="color:#A31515; " - ";
strTag += bstr;
pImgElem->Release();
}<span style="color:Blue; else{
MSHTML::IHTMLAnchorElementPtr pAnchElem;
hr = pDisp->QueryInterface(IID_IHTMLAnchorElement, (<span style="color:Blue; void **)&pAnchElem);
<span style="color:Blue; if(hr == S_OK)
{
pAnchElem->get_href(&bstr);
strTag += <span style="color:#A31515; " - ";
strTag += bstr;
pAnchElem->Release();
}
}
lChLength = MSHTML::IHTMLElementCollectionPtr(pChElem->children)->length;
<span style="color:Blue; if(lChLength)
{
ProcessElem(pChElem);
}
pChElem->Release();
}
}
}
}
pChElemColl->Release();
}
}
}
[/code]
and I want to dynamically create a xml DOM object, as I walk the HTML doc tree structure top-down recursively, but I didnt figure tht out, the hardest part is how to append the child xml node to its parent?
cheers
daiyue
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; void CHTMLBrowserDlg:rocessHTMLDoc(MSHTML::IHTMLDocument2Ptr pDoc)
{
MSHTML::IHTMLElementPtr pElemBody;
HRESULT hr;
hr = pDoc->get_body(&pElemBody);
<span style="color:Blue; if (SUCCEEDED(hr))
{
<span style="color:Green; // Obtained html body element.
ProcessElem(pElemBody);
pElemBody->Release();
}
}
<span style="color:Blue; void CHTMLBrowserDlg:rocessElem(MSHTML::IHTMLElementPtr pElem)
{
HRESULT hr;
<span style="color:Blue; long lLength = 0;
IDispatchPtr pElemDisp = NULL;
MSHTML::IHTMLElementCollectionPtr pChElemColl = NULL;
hr = pElem->get_children(&pElemDisp);
<span style="color:Blue; if(SUCCEEDED(hr))
{
hr = pElemDisp->QueryInterface(IID_IHTMLElementCollection, (VOID**)&pChElemColl);
<span style="color:Blue; if(SUCCEEDED(hr))
{
hr = pChElemColl->get_length(&lLength);
<span style="color:Blue; if(SUCCEEDED(hr))
{
<span style="color:Blue; for(<span style="color:Blue; int i = 0; i < lLength; i++)
{
VARIANT varIndex;
varIndex.vt = VT_UINT;
varIndex.lVal = i;
VARIANT var2;
VariantInit(&var2);
IDispatchPtr pDisp = NULL;
hr = pChElemColl->raw_item(varIndex, var2, &pDisp);
<span style="color:Blue; if(hr == S_OK)
{
MSHTML::IHTMLElementPtr pChElem = NULL;
hr = pDisp->QueryInterface(IID_IHTMLElement, (<span style="color:Blue; void **)&pChElem);
<span style="color:Blue; if(hr == S_OK)
{
CComBSTR bstr;
IDispatchPtr pDispCh = NULL;
<span style="color:Blue; long lChLength = 0;
MSHTML::IHTMLElementCollectionPtr pChColl = NULL;
hr = pChElem->get_tagName(&bstr);
CString strTag = bstr;
MSHTML::IHTMLImgElementPtr pImgElem;
hr = pDisp->QueryInterface(IID_IHTMLImgElement, (<span style="color:Blue; void **)&pImgElem);
<span style="color:Blue; if(hr == S_OK)
{
pImgElem->get_href(&bstr);
strTag += <span style="color:#A31515; " - ";
strTag += bstr;
pImgElem->Release();
}<span style="color:Blue; else{
MSHTML::IHTMLAnchorElementPtr pAnchElem;
hr = pDisp->QueryInterface(IID_IHTMLAnchorElement, (<span style="color:Blue; void **)&pAnchElem);
<span style="color:Blue; if(hr == S_OK)
{
pAnchElem->get_href(&bstr);
strTag += <span style="color:#A31515; " - ";
strTag += bstr;
pAnchElem->Release();
}
}
lChLength = MSHTML::IHTMLElementCollectionPtr(pChElem->children)->length;
<span style="color:Blue; if(lChLength)
{
ProcessElem(pChElem);
}
pChElem->Release();
}
}
}
}
pChElemColl->Release();
}
}
}
[/code]
and I want to dynamically create a xml DOM object, as I walk the HTML doc tree structure top-down recursively, but I didnt figure tht out, the hardest part is how to append the child xml node to its parent?
cheers
daiyue
View the full article