2012-02-10 5 views
1

캐스팅 방법 mshtml.IHTMLDivElement to mshtml.HTMLDivElementClass?mshtml.HTMLDivElementClass에 mshtml.IHTMLDivElement를 캐스팅하는 방법은 무엇입니까?

IHTMLElementCollection collection = doc.body.all; 

foreach (var htmlElem in collection) 
{ 
    if (htmlElem is mshtml.IHTMLDivElement) 
    { 
     mshtml.IHTMLDivElement div = htmlElem as mshtml.IHTMLDivElement; 
     if (div != null) 
     { 
      // HTMLDivElementClass divClass = (HTMLDivElementClass)div; ?????????      
     } 
    }    
} 

모든 구성원을 확보하려면 HTMLDivElementClass에 액세스해야합니다.

enter image description here

+0

왜 캐스트를해야합니까? 주석 처리 된 코드의 문제점은 무엇입니까? – vcsjones

+0

@vcsjones HTMLDivElementClass 안에 필요한 모든 속성에 액세스 할 수 없기 때문에. IHTMLDivElement에는 2 개의 속성 만 있습니다 ... 예를 들어 DIV 등의 ID를 가져와야합니다. –

답변

1

귀하의 코드는 거의 정확. 당신이 원하는 것을 모릅니다. 당신은 모든 DIV 원한다면

그것은 나를 위해와에서 일하고

mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.body.all; 

      foreach (var htmlElem in collection) 
      { 
       if (htmlElem is mshtml.IHTMLDivElement) 
       { 
        mshtml.HTMLDivElementClass div = htmlElem as mshtml.HTMLDivElementClass; 
        if (div != null) 
        { 
        //DO YOUR CODE HERE 
        //div.IHTMLElement_id 
        } 
       } 
      } 

아래처럼 코드를 변경하십시오 "DIV"개체 유형 "HTMLDivElementClass"

그리고 또 하나의 제안입니다 태그 만 다음 페이지에서 다음 코드 줄을 사용하십시오. 요소를 확인하는 당신의 상태를 제거하는 대신

mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.body.all; 

mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.getElementsByName("div"); 

는 DIV 여부입니다.

이 도움을 받으십시오.