Friday, December 28, 2012

GetChildElemetsByTagName VC++


///Get child elements by tag name
IHTMLElementCollection* CTest::GetChildElemetsByTagName(IHTMLElement* pElem,CString TagName)
{
IDispatch* pDisp = NULL;
IDispatch *pdispSpan;
IHTMLElement *peltSpan;

pElem->get_all(&pDisp);

IHTMLElementCollection* pFormColl = NULL;
HRESULT hr = pDisp->QueryInterface(IID_IHTMLElementCollection, (void**)&pFormColl);

pFormColl->tags(CComVariant(TagName.AllocSysString()),&pdispSpan);

CComQIPtr pEltColl2(pdispSpan);

return pEltColl2;
}


//Access this collection

void CTest::ChangeId(IHTMLElement* objElem, int Seq)
{

IHTMLElementCollection *pElemClc= GetChildElemetsByTagName(objElem,"p");

long lPCount;
BSTR tempBSTR;

pElemClc->get_length(&lPCount);
IHTMLElement *pElem;

for(int iIndex=0;iIndex {
//Get first header elem
CComPtr pdispSpan2;
pElemClc->item(CComVariant(iIndex), CComVariant(iIndex), &pdispSpan2);
pdispSpan2->QueryInterface(&pElem);

VARIANT objAttr;
pElem->getAttribute(_bstr_t("name"),1,&objAttr);
CString AttribVal(objAttr.bstrVal);

       }
}

No comments:

Followers

Link