C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[46245] Re:mshtml 사용해 보신 분 get_children이나 IHTMLAttributeCollection사용법을 알고 싶습니다.
leo21c [leo21c] 2747 읽음    2006-08-19 11:08
자답이네요. MSDN에서 자료 찾았습니다.
계발중인 것은 아직 다른 부분에서 문제가 있지만 이곳에 올린 질문에 대한 답은 찾았습니다.

데브피아에 올린 글에 답변과 같습니다. 저도 MSDN 예제 확인했구요.
혹시 필요하신 분이 계실지도 몰라 글남깁니다.

'pElem->get_tagName(&bstr);' 이 있는 부분에서 get_children(..) 을 사용하시면 될 것으로 보입니다.

IDispatchPtr spDisp;
pElem->get_children(&spDisp);
if(spDisp != NULL)
{
    IHTMLElementCollectionPtr spElements;
    spDisp->QueryInterface(IID_IHTMLElementCollection, (LPVOID*)&spElements);
}
이런식으로 하시면 될 것으로 보입니다.

IHTMLAttributeCollection 의 사용법은 MSDN에 있는 예제를 올려드립니다.


IHTMLDOMNode* pElemDN;
IDispatch* pACDisp;
IHTMLAttributeCollection* pAttrColl;
IDispatch* pItemDisp;
IHTMLDOMAttribute* pItem;

LONG lACLength;
VARIANT vACIndex;
BSTR bstrName;
VARIANT vValue;
VARIANT_BOOL vbSpecified;

m_pElem->QueryInterface(IID_IHTMLDOMNode, (void**)&pElemDN);
pElemDN->get_attributes(&pACDisp);
pACDisp->QueryInterface(IID_IHTMLAttributeCollection, (void**)&pAttrColl);
pAttrColl->get_length(&lACLength);

vACIndex.vt = VT_I4;
for (int i = 0; i < lACLength; i++)
{
    vACIndex.lVal = i;
    pAttrColl->item(&vACIndex, &pItemDisp);
    pItemDisp->QueryInterface(IID_IHTMLDOMAttribute, (void**)&pItem);
    pItem->get_specified(&vbSpecified);
    pItem->get_nodeName(&bstrName);
    pItem->get_nodeValue(&vValue);
    pItemDisp->Release();
    pItem->Release();
}

pElemDN->Release();
pACDisp->Release();
pAttrColl->Release();

-----------------------------------------------------------------------------------


leo21c 님이 쓰신 글 :
: 자료를 찾아보고 mshtml을 이용해서 만들어 보았습니다.
: 각 tag(element)의 child element 유무와 child element를 가져오고 싶은데
: parent element를 가져오는 방법은 있어도 child element를 가져오는 방법은
: 모르겠습니다.

: 소스는 이렇습니다. 아래와 같이 하면 HTML의 모든 tag이름을 확인할 수 있습니다.
: 저는 각 tag(element)별 내용을 가져오고 싶습니다. 또한 element에 있는 attribute값도
: 확인하고 싶습니다.
:
: MSDN을 열심히 보고 있는데 잘 모르겠습니다. MSHTML에 대한 예제가 거의 없네요.
: 제가 하고 있는 프로젝트는 HTML의 VML 데이터를 읽어와서 화면에 이미지를 보이도록
: 하는 것입니다. VML 데이터를 가지고 있는 각 Element와 attribute 값이 필요합니다.
:
:
: ---------------------------------------------------------------------------------
:
:   IDispatch *pDocument=CppWebBrowser1->Document;
:   HRESULT hr;
:
:   IHTMLDocument2* pDoc=NULL;
:   hr=pDocument->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pDoc);
:   pDocument->Release();
:   if(!pDoc) return;
:
:   IHTMLElementCollection* pElemCol = NULL;
:
:   hr = pDoc->get_all(&pElemCol);
:   pDoc->Release();
:
:   if(!pElemCol) return;
:
:   Memo1->Align = alClient;
:   Memo1->Lines->Clear();
:
:   long lLength = 0;
:   hr = pElemCol->get_length(&lLength);
:
:   AnsiString memo;
:   BSTR bstr = NULL;
:   IHTMLElement* pElem = NULL;
:   for(int i=0; i<lLength; i++)
:   {
:     VARIANT varIndex;
:     varIndex.vt = VT_UINT;
:     varIndex.lVal = i;
:     VARIANT var2;
:     VariantInit( &var2 );
:     IDispatch* pDisp;
:
:     hr = pElemCol->item(varIndex,var2, &pDisp );
:
:     if(pDisp){
:       if(pElem) pElem->Release();
:       pDisp->QueryInterface(IID_IHTMLElement, (LPVOID*)&pElem);
:       pDisp->Release();
:       if(!pElem) continue;
:       pElem->get_tagName(&bstr);
:
:       AnsiString strTag = bstr;
:       AnsiString attrString;
:       WideString tValue;
:       BSTR attr = SysAllocString(L"lang");
:
:       VARIANT AttributeValue;
: //      attrString = (LPCTSTR)bstr_t(pElem->getAttribute(L"meta", 2, &AttributeValue));
:
:       hr=pElem->getAttribute(attr, 0, &AttributeValue);
:       if (hr == S_OK) {
:         tValue = (BSTR)AttributeValue.bstrVal;
:         attrString = tValue;
:       }
:       SysFreeString(attr);
:       pElem->Release();
:       pElem = NULL;
:
:       Memo1->Lines->Add(strTag);
:       Memo1->Lines->Add("\n");
:     }
:   }
:   pElemCol->Release();
: -----------------------------------------------------------------------------

+ -

관련 글 리스트
46218 mshtml 사용해 보신 분 get_children이나 IHTMLAttributeCollection사용법을 알고 싶습니다. leo21c 1298 2006/08/17
46245     Re:mshtml 사용해 보신 분 get_children이나 IHTMLAttributeCollection사용법을 알고 싶습니다. leo21c 2747 2006/08/19
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.